0% found this document useful (0 votes)
22 views57 pages

Chap5 Database 1

Uploaded by

patilvashra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views57 pages

Chap5 Database 1

Uploaded by

patilvashra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

Q. QUESTION 7.

______moves the cursor to the specified row


1. A. public boolean absolute(int row)
_______calls get converted into native C or C++
B. public boolean relative(int row)
API calls.
C. public boolean getRow(int row)
A. API
D. public void currentRow()
B. JDBC
Answer: A
C. JDBC Native API
D. none
8. A benefit of the three-tier architecture is which
Answer: C
of the following?
2. A. New modules can be built to support specific
________ is an interface by which application
business needs.
programs can access and process SQL
B. Performance improves for compiled SQL
databases in a DBMS-independent manner.
statements
A. ODBC
C. Results in a thinner client and database server
B. OLE DB
D. All of the above
C. JPCD
Answer: A
D. ADO
Answer: A
9. A Java program cannot directly communicate
3. with an ODBC driver because
________ loads database drivers and manages
A. ODBC written in C language
the connection between application and the
B. ODBC written in C++ language
driver.
C. ODBC written in C# language
A. Driver
D. ODBC written in Visual Basic language
B. DriverManager
Answer: A
C. Statement
D. PreparedStatement
10. Abbreviate the term DSN
Answer: B
A. Digital Source Name
4. B. Data Socket Name
__________interface allows storing results of
C. Data String Name
query?
D. Data Source Name
A. Statements
Answer: D
B. Connection
C. ResultSet
11. Advantages of Type4 driver are
D. none
Answer: C A. Completely written in Java and no need of
ODBC
5. B. Completely written in Java and need of ODBC
________________ method is used to execute
C. Partially written in java and ODBC is needed
only the ‘SELECT’ query of the SQL.
D. ODBC and JDBC are to be installed
A. executeSelect()
Answer: A
B. execute()
C. executeQuery()
12. All input parameters in JDBC are represented
D. executeUpdate()
Answer: C by _____ symbol, which is known as ______.
A. * , parameterized cursor
6. B. * , place holder
__________is logical set of rows and columns
C. ? , parameterized cursor
of data returned by executing SQL statement.
D. ? , place holder
A. Statement
Answer: D
B. Connection
C. Table
13. API is which of the following
D. ResultSet
Answer: D A. The same thing as ODBC.
B. Middleware that does not provide access to
database
C. Middleware that provide access to database. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
D. The same thing as JDBC. Connection con=__________("jdbc:odbc:mydsn");
Answer: C Statement stmt=con.createStatement();
A. DriverManager.getStatement
14. boolean execute() method returns B. DriverManager.getConnection
A. Result set object C. DriverManager.setConnection
B. Boolean values D. None of above
C. Multiple results Answer: B
D. All of above
Answer: C 21. Following is example of which jdbc query?
ResultSet rs = stmt.executeQuery("select * from
15. Connection con = DriverManager. getConnection(url); emp");
This command will create the following: while(rs.next())
A. new con object of connection class initiated {
with connection of content of url class System.out.println(rs.getInt(1)+" “
B. new url object of connection class initiated +rs.getString(2));
with connection of content of con class }
C. new connection is established directly by con A. executeQuery() method
and urlobjectss B. createStatement() method
D. None of the above C. close() method
Answer: A D. createStatement() method
Answer: A
16. Connection is __________
A. Class 22. For execution of DELETE SQL query in JDBC,
B. Interface ............. method must be used.
C. Method A. executeQuery()
D. Abstract Class B. executeDeleteQuery()
Answer: B C. executeUpdate()
D. executeDelete()
17. Connection object can be initialized using the Answer: C
_______ method of the Driver Manager class.
A. putConnection() 23. For execution of UPDATE SQL query in JDBC
B. setConnection() _____________ method is used.
C. Connection() A. executeQuery()
D. getConnection() B. executeUpdate()
Answer: D C. execute()
D. All of these
18. DELETE statement of an SQL is executed by __. Answer: B
A. execute()
B. executeQuery() 24. For JDBC which of the following package is used
C. executeUpdate() A. java.sql
D. executeDelete() B. java.jbl
Answer: C C. java.net
D. all of above
19. Disadvantage of Type 1 jdbc-odbc driver is ___ Answer: A
A. Easy to use
B. It is free, no charges 25. getConnection() method have which
C. Dependent on ODBC driver parameters: _________
D. Easy connectivity A. URL-JdbclOdbc:DSN, String Username, String
Answer: C Password
B. URL-OdbclJdbc:DSN
20. Fill correct data in following part of the code: C. Both A and B
D. None of Above A. index of column
Answer: A B. index of row
C. index of Question mark
26. getConnection() method of DriverManager D. index of Resultset
returns __________________________ Answer: C
A. Driver Object
B. ResultSet object 32. In the following JDBC drivers which is known as
C. Connection Object partially java driver?
D. DataSet Object A. JDBC-ODBC bridge driver
Answer: C B. Native-API driver
C. Network Protocol driver
27. getResultSet() method belongs to _________. D. Thin driver
A. Statement interface Answer: B
B. Connection interface
C. ResultSet interface 33. In three tier model, middle tier of the services
D. DriverManager interface acts as a mediator between _____ and _____.
Answer: A A. Java applet and DBMS
B. Java application and databases
28. How will JDBC help the programmers to write C. Data source and Application server
java applications that manage programming D. DBMS and user
activities: Answer: B
A. It helps us to connect to a data source, like a
database. 34. In the three-tier model, commands are sent to
B. It helps us in sending queries and updating a middle tier of services, which then send SQL
statements to the database statements to the _______________
C. Retrieving and processing the results received A. Client
from the database in terms of answering to your B. Server
query. C. Database
D. All of Above D. JDBC
Answer: D Answer: C

29. Identify the invalid method of DriverManager- 35. JDBC stands for ________.
A. registerDriver() A. Java Database Connectivity
B. deregisterDriver() B. java database components
C. getConnection() C. java database controls
D. openConnection() D. None of the above
Answer: D Answer: A

30. In DriverManager class which method is used 36. Native-API driver converts JDBC calls into ____
to establish the connection with specified url A. ODBC calls
A. public static void deregisterDriver(Driver B. vendor specific database network protocol
driver) C. user calls
B. public static void registerDriver(Driver driver) D. native calls of the database API
C. public static Connection getConnection(String Answer: D
url)
D. public static Connection getConnection 37. ODBC Drivers are platform _______________
(String url,String userName,String password) A. Dependent
Answer: C B. Indepndent
C. Dependent,Independent
31. In setXXX() methods used for Prepared- D. All of above
Statement the first argument specifies which Answer: A
value?
38. PreparedStatement interface creates an object times?
that represents a ________________ String sqlInsert = "insert into books values (3001,
A. Compiled SQL Statement 'Gone Fishing', 'Kumar', 11.11, 11)";
B. Precompiled SQL Statement int countInserted = stmt.executeUpdate(
C. Select SQL Statement sqlInsert);
D. Insert SQL Statement System.out.println(countInserted + " records
Answer: B inserted.n");
A. records inserted
39. public class DriverManager extends B. 1 records inserted
A. Object C. null records inserted
B. String D. 2 records inserted
C. Connection Answer: A
D. Statement
Answer: A 45. The _____ package contains classes that help in
connecting to a database, sending SQL
40. Rearrange the steps to connect to the database statements to the database and processing the
in SQL query results.
a. Create the connection object A. connection.sql.*
b. Execute the query B. db.sql.*
c. Close the connection object C. pkg.sql.*
d. Register the driver class D. java.sql.*
e. Create the statement object Answer: D
A. a-b-c-d-e
B. d-a-e-b-c 46. The _____ method can be used on a ______
C. e-d-c-b-a object to create its meta data object
D. d-a-c-b-e A. getMetaData(),ResultSet
Answer: B B. executeQuery(),ResultSet
C. executeUpdate(),ResultSet
41. ReslutSetMetaData Interface Object created by D. execute(),ResultSet
_______ method, of _______ interface. Answer: A
A. getMetaData(), ResultSet
B. getMetaData(), Statement interface 47. The _____ driver resolves JDBC call and makes
C. getResultSet(), PreparedStatement interface equivalent ODBC Call
D. getMetaData(), DatabaseMetaData interface A. JDBC Native API
Answer: A B. JDBC-Net pure java
C. 100% pure java
42. Return type of executeQuery() method is ____ D. JDBC-ODBC bridge
A. Int Answer: D
B. ResultSet
C. Void 48. The ----------------- method executes a simple
D. Statement query and returns a single Result Set object
Answer: B A. ExecuteUpdate
B. executeQuery()
43. Set XXX() method binds values to the C. execute()
parameters. Where XXX represents D. noexecute()
A. Data Type Answer: B
B. Object
C. Both a & b 49. The ........................ object allows you to
D. None of above execute parameterized queries.
Answer: A A. ResultSet
B. Parametrized
44. What will be output if I execute the code 2 C. PreparedStatement
D. Condition C. after the first row
Answer: C D. previous row from the current position
Answer: A
50. The correct string for loading Jdbc-Odbc bridge
driver using Class.forName() method is: 56. The Type 3 architecture is _______________
A. jdbc.odbc.JdbcOdbcDriver A. JDBC-Net pure Java
B. microsoft.odbc.jdbc.OdbcJdbcDriver B. JDBC-Native API
C. sun.jdbc.odbc.JdbcOdbcDriver C. JDBC-ODBC Bridge Driver
D. microsoft.sun.JdbcOdbcDriver D. All of the above
Answer: C Answer: A

51. The executeQuery( String sql) method is used 57. The valid constant to represent ResultSet type
to execute ______ query & it returns _______ is ___________________
A. CREATE , integer A. TYPE_FORWARD_ONLY
B. INSERT ,single row B. TYPE_SCROLL_SENSITIVE
C. SELECT , ResultSet object C. TYPE_SCROLL_INSENSITIVE
D. DELETE , ResultSet object D. All of the mentioned
Answer: C Answer: D

52. The JDBC-ODBC bridge driver resolves _______ 58. To execute a SELECT statement "select * from
& makes equivalent _________ Address" on a Statement object stmt, use
A. JDBC call, ODBC call A. stmt.execute("select * from Address");
B. ODBC call, ODBC call B. stmt.executeQuery("select * from Address");
C. ODBC call, JDBC call C. stmt.executeUpdate("select * from Address");
D. JDBC call, JDBC call D. stmt.query("select * from Address");
Answer: A Answer: B

53. The Prepared statement object is used ______ 59. To retrieve a Connection object,………………….
A. to call the stored procedures from within a Method is used.
JDBC application program A. connection( )
B. IN, OUT, INOUT parameters when calling a B. establish( )
stored procedure C. getConnection( )
C. to execute dynamic SQL statement against D. getConnected( )
the database. Answer: C
D. to both pass information and retrieve
information from a stored procedure. 60. Type 1 driver is also known as
Answer: C A. JDBC-Native API
B. JDBC-ODBC Bridge Driver
54. The PreparedStatement__________symbol is C. JDBC-net pure java
placeholder that is replaced by the input D None of these
parameter at seen time. Answer: B
A. *
B. ? 61. Using JDBC you can send SQL, PL/SQL
C. # statements ___________________
D. @ A. to almost any relational database.
Answer: B B. to MySQL database
C. to MSAccess
55. The ResultSet object maintains a cursor D. to Oracle
pointing to a particular row of data. Initially, Answer: A
cursor points to ___________
A. before the first row 62. Valid constant to set ResultSet as Scrollable is
B. next row from the current position _____________________
A. ResultSet.TYPE_FORWARD_ONLY B. A DataSource is the Java representation of a
B. ResultSet.TYPE_SCROLL_SENSITIVE physical data source
C. ResultSet.TYPE_SCROLL_INSENSITIVE C. A DataSource is a registry point for JNDI-
D. All of above services
Answer: D D A DataSource is a factory of connections to a
physical data source
63. What are types of JDBC driver? Answer: D
A. JDBC-ODBC bridge
B. JDBC native API 69. What maintains a cursor that points to a
C. pure java JDBC network particular row of data. Initially, cursor points to
D. all the above before the first row?
Answer: D A. Connection interface
B. Statement interface
64. What contains object specific to database, and C. ResultSet object
used to create Connection object from the D. None of the Above
options? Answer: C
A. Driver Interface / Connect()
B. ResultSet 70. What MySQL property is used to create a
C. Statement surrogate key in MySQL?
D. Driver Manager A. UNIQUE
Answer: A B. SEQUENCE
C. AUTO_INCREMENT
65. What is error in this statement? D. None of the above -- Surrogate keys are not
class.forName("sun.jdbc.odbc.jdbcodbcDriver"); implemented in MySQL.
url="xyz" connection con= DriverManager. Answer: C
getConnection(url);
A. unidentified string 71. What the following statement returns?
B. object not created properly SQLWarning warning = statement.
C. no correction in code getWarnings();
D. driver name is wrong System.out.println("Message: " + warning.
Answer: D getMessage());
A. Output of Warning
66. What is return type of execute() method? B. Warning number
A. object of ResultSet class C. Description about SQL warning
B. integer D. Displays "Message"
C. void Answer: C
D. boolean
Answer: D 72. What will be the result of executing the
following code snippet?
67. What is the disadvantage of Type-4 Native- Statement sql2 = con.createStatement();
Protocol Driver? int result=sql2.executeUpdate("Select * From
A. At client side, a separate driver is needed for Publishers");
each database. A. Will throw an exception
B. Type-4 driver is entirely written in Java B. Will result in compilation error
C. The driver converts JDBC calls into vendor- C. Will return the number of rows retrieved from
specific database protocol Publishers table
D. It does not support to read MySQL data. D. Will return null
Answer: A Answer: B
(Error: statement does not generate a row count)
68. What is, in terms of JDBC, a DataSource?
73. When a connection is created, by default it is in
A. A DataSource is the basic service for
managing a set of JDBC drivers _____________
A. rollback mode the database?
B. execute mode A. DatabaseSetMetaData
C. select mode B. DatabaseMetaData
D. auto commit mode C. ResultSetMetaData
Answer: D D. ResultSet
Answer: B
74. Where is Metadata stored in MYSQL?
A. In MYSQL database Metadata 81. Which is a correct component of JDBC API
B. In MYSQL database Metasql A. DriverManager
C. In MYSQL database Mysql B. Driver
D. None of above C. PreparedStatement
Answer: C D. both a & b
Answer: D (?)
75. Which driver is called as a thin driver in JDBC?
A. Type-1 Driver 82. Which is not a Navigation method of ResultSet
B. Type-2 Driver interface
C. Type-3 Driver A. next()
D Type-4 Driver B. last()
Answer: D C. beforeLast()
D. beforeFirst()
76. Which driver type use middleware Answer: C
server(Application Server)?
A. Type 1 83. Which is the Jdbc-Odbc bridge driver?
B. Type 2 A. microsoft.jdbc.odbc.JdbcOdbcDriver
C. Type 3 B. sun.jdbc.odbc.JdbcOdbcDriver
D. Type 4 C. com.mysql.jdbc.Driver
Answer: C D. oracle.jdbc.odbc.JdbcOdbcDriver
Answer: B
77. Which from the below use "middle-tier"
A. Three-Tier 84. Which JDBC driver maps the JDBC calls to the
B. Four-Tier native method calls, which are
C. n-Tier passed to the local native Call Level Interface
D. All of above (CLI)?
Answer: D A. Native-API-Partly-Java driver
B. JDBC-ODBC Bridge driver
78. Which interface have following methods C. Native Protocol Pure-Java driver
clearParameter(),setInt(),execute(). D. JDBC-Net-Pure-Java driver
A. CallableStatement interface Answer: A
B. connection interface
C. preparedStatement interface 85. Which JDBC driver Type(s) can you use in a
D. statement interface three tier architecture and if the web server
Answer: C and the DBMS are running on the same
machine
79. Which Interface is used to execute dynamic SQL A. Type-1
statements? B. Type-2
A. Resultset C. Type3 and 4
B. PreparedStatement D. All of above
C. Statement Answer: D
D. ResultSetMetaData
Answer: B 86. Which JDBC driver Type(s) is (are) the JDBC-
ODBC bridge?
80. Which interface gives information related to A. Type-1
B. Type-2 D. executeQuery()
C. Type-3 Answer: A
D. Type-4
Answer: A 93. Which object allows you to create
parameterized queries?
87. Which JDBC driver Types are for use over A. ResultSet
communications networks? B. PreparedStatement
A. Type 3 only C. Statement
B. Type 4 only D. Condition
C. Both Type 3 and Type 4 Answer: B
D. Neither Type 3 nor Type 4
Answer: C 94. Which of the following class is used for
establishing connection?
88. Which list gives a quick way to determine A. DriverManager
which Connection method is appropriate for B. Connection
creating different types of SQL statements? C. Statement
A.createStatement D. ResultSet
B.prepareStatement Answer: A
C.prepareCall
D.All of the mentioned above 95. Which of the following function is used to find
Answer: D the column count of the particular ResultSet?
A. getMetaData()
89. Which maintains a cursor pointing to a B. MetaData()
particular row of data initially ,cursor points to C. getColumnCount()
before the first row ? D. getCount()
A. Connection interface Answer: C
B. Statement interface
C. Resultset interface 96. Which of the following is a following statement
D. None of the above is a prepared statements?
Answer: C A. Insert into department values(?,?,?)
B. Insert into department values(x,x,x).
90. Which method is used for saving records in a C. SQLSetConnectOption(conn, SQL
database? AUTOCOMMIT, 0)
A. commit() D. SQLTransact(conn, SQL ROLLBACK)
B. commit once() Answer: A
C. single Commit()
D. None of the Above 97. Which of the following is not a
Answer: A component/class of JDBC API?
A. Statement
91. Which method is used to send CREATE TABLE B. ResultSet
queries to database using JDBC? C. SQLException
A. executeQuery() D ConnectionPool
B. executeUpdate() Answer: D
C. createTable()
D. insertNewTable() 98. Which of the following is not method of
Answer: B DriverManager class
A. registerDriver(Driver driver)
92. Which method of class is used to register & B. getConnection(String url)
dynamically load the driver class? C. deregisterDriver(Driver driver)
A. forName() D. None of these
B. getConnection() Answer: D
C. createStatement()
99. Which of the following is not true for pure Java driver that uses a middleware driver
Statement and PreparedStatment? to connect to a databse?
A. Standard Statement is used to create a Java A. Type-1 Driver
representation of a literal SQL statement and B. Type-2 Driver
execute it on the database. A Prepared- C. Type-3 Driver
Statement is a precompiled statement. D. Type-4 Driver
B. Statement use for general purpose access and Answer: C
PreparedStaement use when you plan to use
SQL Statement Many times. 105. Which of the following method is used for
C. Statement is use when you are using static SELECT query?
SQL Statements and PreparedStatement is use A. execute()
to access parameter at run time B. execute(String sql);
D. None of above C. executeUpdate()
Answer: D D. executeQuery(String sql);
Answer: D
100. Which of the following is the correct syntax of
executeQuery() method? 106. Which of the following method is used for
A. int executeQuery() sending SQL statements
B. int executeQuery(String str) A. Statement
C. ResultSet executeQuery() B. Callablestatement()
D. ResultSet executeQuery(String str) C. Preparedstament
Answer: D D. Both C & B
Answer: A
101. Which of the following is true about JDBC
architecture? 107. Which of the following method is used to load
A. JDBC API layer provides the application-to- drivers for database?
JDBC Manager connection. A. forName()
B. JDBC Driver API layer supports the JDBC B. loadDriver()
Manager-to-Driver Connection C. installDriver()
C. Both of the above. D. None of these
D. None of the above. Answer: A
Answer: C
108. Which of the following statement is true in case
102. Which of the following is used to access the security consideration for JDBC:
database server at time of executing the i] Normal unsigned applets are generally
program and get the data from the server untrustworthy.
accordingly? ii] Downloaded driver should be used for
A. Embedded SQL connection purpose only.
B. Dynamic SQL iii] No automatic or implicit use of local
C. SQL declarations credentials while connecting to remote database
D. SQL data analysis servers.
Answer: B iv] Untrusted applets should not be permitted to
access to local database data.
103. Which of the following is used to call stored A. i and ii true
procedures on the database? B. ii and iii true
A. Statement C. i and iii true
B. PreparedStatement D. All of the above
C. CallableStatement Answer: D
D. None of the above
Answer: C 109. Which of the following statements is true
concerning JDBC?
104. Which of the following JDBC Driver refers to a A. It is Useful for all object-oriented language
B. It consist three main layers. B. javax.net
C. It is similar concept to ODBC. C. java.jdbc
D. It is language independent. D. java.lang
Answer: C Answer: A

110. Which of the following type of JDBC driver is 114. Which packages contain the JDBC classes?
the fastest one? A. java.jdbc and javax.jdbc
A. Type 4 B. java.jdbc and java.jdbc.sql
B. Type 2 C. java.sql and javax.sql
C. Type 3 D. java.rdb and javax.rdb
D. Type 1 Answer: C
Answer: A
115. Which statements about JDBC are true?
111. Which of the following type of JDBC driver i] JDBC is an API to connect to relational-, object-
should be used when you are accessing one and XML data sources
type of database, such as Oracle, Sybase, or ii] JDBC stands for Java DataBase Connectivity
IBM? iii] JDBC is an API to access relational databases,
A. Type 1 spreadsheets and flat files
B. Type 2 iv] JDBC is an API to bridge the object-relational
C. Type 3 mismatch between OO programs and relational
D. Type 4 databases
Answer: D A. i-true, iv-true
B. ii-true, iii-true
112. Which one of the following will not get the data C. i-true, ii-true
from the first column of ResultSet rs, returned D. iii-true, iv-true
from executing the following SQL statement: Answer: B
SELECT name, rank, serial No FROM employee?
A. rs.getString(0) 116. You can add a row using SQL in a database with
B. rs.getString("name") which of the following?
C. rs.getString(1) A. ADD
D. None of the Above B. CREATE
Answer: A C. INSERT
D. MAKE
113. Which package need to be imported for Answer: C
establishing connection with database
A. java.sql

Sr.
QUESTION
No.
1. _________________________ identify component

A. Application Server
B. DBMS
C. Host
D. Proxy
Answer: B

2. Consider above table and to extract marks of student whose name AJP, which will be correct
form of ResultSet class method:

Note: r1 is object of ResultSet class


A. r1.absolute(4), r1.getInt(2)
B. r1.absolute(3), r1.getInt(2)
C. r1.absolute(3), r1.getInt(3)
D. r1.absolute(4), r1.getInt(3)
Answer: A

3. Which code is correct to generate the given output?

A. PreparedStatement p=c.prepareStatement("Select * from Employee where Name='Ram'");


B. Preparedstatement p=c.prepareStatement("Select * from Employee where Name='Ram'");
C. PreparedStatement p=c.PrepareStatement("Select * from Employee where Name='Ram'");
D. PreparedStatement p=c.prepareStatement("Select * from Employee where Name=Ram);
Answer: A

4. Analyse the following code and fill the appropriate statement in ___________________.
import java.sql.*;
class Record
{
public static void main(String args[])throws Exception
{
Class.forName("jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydsn");
PreparedStatement stmt=con.prepareStatement("select * from emp where EmpName=?");
stmt.______________
ResultSet rs=stmt.executeQuery();
System.out.println("EmpNametDesignationtSalary");
where(rs.next())
{
System.out.println(rs.getString(1)+"t"+rs.getString(2)+"t"+rs.getInt(3));
}
con.close();
}
A. setString(0,"Rahul");
B. setString(0,'Rahul');
C. setString(1,"Rahul");
D. setString(1,'Rahul');
Answer: C

5. Analyse the following code and find out missing statement.


import java.sql.*;
class Record
{
public static void main(String args[])throws Exception
{
Connection con=DriverManager.getConnection("jdbc:odbc:xyz");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp where id=101");
System.out.println("EmpNametDesignationtSalary");
where(rs.next())
{
System.out.println(rs.getString(2)+"t"+rs.getString(3)+"t"+rs.getInt(4));

}
con.close();
}
}
A. Missing semicolon
B. Missing {
C. Missing driver registration statement
D Missing }
Answer: C

6. Choose missing statements in following code from given options.


import java.sql.*;
class DBTest
{
public static void main(String args[])
{
try
{
Class.ForName("sun.jdbc.odbc,JdbcOdbcDriver");
System.out.println("Driver Loaded");
String url="jdbc:odbc:xyz";

Connection con=DriverManager.getConnection(url);
System.out.println("Connection to database is created");
Statement st=con.createStatement();
System.out.println("Statement Object is created");
catch(SQLException e)
{
System.out.println("SQL Error");
}
catch(Exception e)
{
System.out.println("Error");
}
}
}
A. { missing
B. ; missing
C. URL class missing
D. } missing
Answer: D

7. Choose missing statements in following code from given options.


import java.sql.*;
class DemoFetch1
{
public static void main(String args[])
{
Connection con;
PreparedStatement pstmt;
ResultSet rs;
String qry,url;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="Jdbc:Odbc:studdsn";
con=DriverManager.getConnection(url,"","");
qry="select * from stud";
pstmt=con.prepareStatement(qry);
rs=___________________;
System.out.println("Roll NotNametPercentage");
while(rs.next())
{
int rno=rs.getInt("roll");
String nm=rs.getString("sname");
double per=rs.getDouble("per");
System.out.println(rno+"t"+nm+"t"+per);
}
con.close();
}catch(Exception e){System.out.println(e.toString());}
}
}
A. pstmt.executeUpdate(qry)
B. pstmt.executeUpdate()
C. pstmt.executeQuery(qry)
D. pstmt.executeQuery()
Answer: D

8. Choose missing statements in following code from given options. import java.sql.*;
class StudentData
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:stud");
PreparedStatement ps = con.prepareStatement("select *from Student where Marks > ?");
ps.setInt(1,70);
ResultSet rs = ps.*******************;
System.out.println("Students having marks > 70 are:");
while(rs.next())
System.out.println(rs.getString(2));
con.close();
}
catch(Exception e){ }
}
}
A. executeQuery()
B. execute()
C. executeUpdate()
D. resultSet()
Answer: A

9. Choose the correct alternative to update employee table


A.
Statement pstmt = null;
try
{
String SQL = "Update Employees SET age = ? WHERE id = ? ";
pstmt = conn. prepareStatement (SQL);

}
catch (SQLException e )
{ … }
finally
{
pstmt. Close ();
}

B.
PreparedStatement pstmt = null;
try
{
String SQL = "Update Employees SET age = ? WHERE id = ? ";
pstmt = conn. prepareStatement (SQL);

}
catch (SQLException e )
{ … }
finally
{
pstmt. Close ();
}
C.
prepareStatement pstmt = null;
try
{
String SQL = "Update Employees SET age = ? WHERE id = ? ";
pstmt = conn. prepareStatement (SQL);

}
catch (SQLException e )
{ … }
finally
{
pstmt. Close ();
}

D.
both a and c
Answer: B

10. Choose the correct option to establish a connection to database named student and display
its contents.
A. import java.sql.*;
class OracleCon{
public static void main(String args[])throws Exception
{
try{
Class.forName("oracle.jdbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

B. static InetAddress[ ] getAllByName(String hostName)

C. import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
Result rs=s.executeQuery("Insert into table STUDENT");
}

D. import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
ResultSet rs=s.executeQuery("select * from stud");
}
Answer: A

11. Choose the correct output for the given code:


import java.sql.*;
class Mydatabase1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
Connection c=DriverManager.getConnection("jdbc:odbc:MYDSN"," "," ");
System.out.println("Connection Established");
Statement st=c.createStatement();
ResultSet rs=st.executeQuery("Select * from StudTable");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getString(2));
}
rs.close();
st.close();
c.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

A.
B.

C.

D.

Answer: A

12. Find the error in following code:


Connection con = DriverManager.getConnection ("jdbc:odbc:wombat", "login", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
while (rs.next())
{
Integer x = rs.getInt("c");
String s = rs.getString("a");
Float f = rs.getFloat("b");
}
A. Retrieval of the fields is in the wrong order.
B. The password must be encrypted before being sent to the DriverManager.
C. The Driver's URL is in the wrong format.
D. The ResultSet class returns primitive types for integers and floats
Answer: A

13. Consider following code. What is an ouput of given code?


import java.sql.*;
class Rsmd{
public static void main(String args[]){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mydsn");
PreparedStatement ps=con.prepareStatement("select * from employee");
ResultSet rs=ps.executeQuery();

ResultSetMetaData rsmd=rs.getMetaData();
System.out.println("Total columns: "+rsmd.getColumnCount());
System.out.println("Column Name of 1st column: "+rsmd.getColumnName(1));
System.out.println("Column Type Name of 1st column: "+rsmd.getColumnTypeName(1));

con.close();
}catch(Exception e){ System.out.println(e);}
}
}

A.
Total columns: 2
Column Name of 1st column: empid
Column Type Name of 1st column: INTEGER

B.
Column Name of 1st column: empid
Column Type Name of 1st column: INTEGER

C.
Total columns: 2
Column Name of 1st column: empid

D.
Total columns: 2
Column Type Name of 1st column: INTEGER
Answer: A

14. Consider the following code, Find the missing statement to get correct output.
public class DeleteRecords
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:DATA");
String query = "delete from tannis";
PreparedStatement pstmt = con.prepareStatement(query);
pstmt.executeUpdate();
pstmt.close();
con.close();
}
catch (Exception e)
{
System.out.println(e);
}

}
}

A. Missing import java.sql.Connection;


B. Missing import java.sql.DriverManager;
C. Missing import java.sql.PreparedStatement;
D. All the above
Answer: D

15. Consider the following code.What should be the correction done in the code to get correct
output?
import java.sql.*;
class mytable
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = ("jdbc:odbc:mystudtable");
Connection con=DriverManager.getConnection(url);
System.out.println("ConnectionEstablished");
Statement studste = con.createStatement();
String studqry = "create table student(rno int,name char)";
studste .execute(qry);
}
catch(SQLException e)
{
System.out.println("databse Connection error.....");
}
catch(Exception e)
{
System.out.println("Other error.....");
}
}
A. replace statement studste.execute(qry) with studste.execute(studqry)
B. missing }
C. missing ;
D. Both option i and ii
Answer: D

16. Consider the following code.What will be student table data after executing this code as table
was empty.
import java.sql.*;
public class mytableins
{
public static void main(String[] args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String s = ("jdbc:odbc:mystudtable");
Connection con=DriverManager.getConnection(s);
System.out.println("Connection Established");
PreparedStatement studste = con.prepareStatement("insert into student values(2,'Rani')");
studste .executeUpdate();
Statement s1 = con.createStatement();
ResultSet Rset = s1.executeQuery( "select * from student");
System.out.println("Roll No ....Name");
while (Rset.next())
{
int studid = Rset.getInt("rno");
String studname = Rset.getString("name");
System.out.println(studid + " " +studname); }

}
}
A. two record will be inserted
B. only one record in table
C. table will be empty
D. error occurs
Answer: B

17. Consider the following program, select the statement that should be added to the program to
get correct output.
import java.sql.*;
public class DBDemo5
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN","","");
PreparedStatement s=c.prepareStatement( "update db3 set Name=? where Roll_no=?");
Statement s=c.createStatement( );
s.setString(1,args[0]);
s.setString(2,args[1]);
s.setString(3,args[2]);
ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"t"+"Roll no"+"t"+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+"t"+rs.getInt(2)+"t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. s.executeUpdate()
B. c.createStatement( )
C. s.close()
D. c.close()
Answer: A

18. Consider the following program, select the statement that should be added to the program to
get correct output.
import java.sql.*;
public class SampleDemo
{
public static void main(String args[])throws SQLException
{
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN","","");
PreparedStatement s=c.prepareStatement( "update db3 set Name=? where Roll_no=?");
Statement s=c.createStatement( );
s.setString(1,args[0]);
s.setString(2,args[1]);
s.setString(3,args[2]);
ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"t"+"Roll no"+"t"+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+"t"+rs.getInt(2)+"t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. s.executeUpdate() Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
B. }
C. s.close() Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
D. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Answer: A

19. Consider the following program, Select the statement that should be added to the program to
get correct output.

import java.sql.*;

public class JdbcOdbc {


public static void main(String args[]) {

try {
Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:datastud");
try {
System.out.println("Getting All Rows from a table!");
Statement st = con.createStatement();
ResultSet res =---------------------------("SELECT * FROM college");
System.out.println("student_code: " + "t" + "student_name: ");
while (res.next()) {
int i = res.getInt("stud_code");
String s = res.getString("stud_name");
System.out.println(i + "tt" + s);
}
con.close();
} catch (SQLException s) {
System.out.println("SQL code does not execute.");
}
} catch (Exception e) {
System.out.println("Error:connection not created");
}

}
}
A. st.createStatement( )
B. st.executeUpdate()
C. st.executeQuery()
D. res.executeQuery()
Answer: C

20. Consider the following program, What will be the output of following Code?
import java.sql.*;
public class db15
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:DSN2","","");
Statement s=c.createStatement( );
int n=s.executeUpdtae("delete from db3");
ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"t"+"Roll no"+"t"+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+"t"+rs.getInt(2)+"t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. Empty Table
B. Table with All Data
C. Error in ResultSet Statement
D. Error in close()
Answer: A

21. Consider the following program, What should be the correction done in the program to get
correct output?
import java.sql.*;
public class MyDB4
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN");
String s= "delete from Employee where emp_id=2";
Statement st=c.createStatement();
int count=ps.executeUpdate(s);
System.out.println("Data deleted"+count);
s="select * from Employee ";
ResultSet rs= st.executeQuery();
while(rs.next())
{
System.out.println(rs.getInt(1)+" tt "+rs.getString(2));
}
s.close(); c.close();
}
}
A. Missing Semicolon
B. Missing {
C. Missing }
D. Missing parameter
Answer: D

22. Consider the following program ,what should be the correction done in the program to get
the correct output
import java.sql.*;
public class displayemployee
{
public static void main(String[] args)
{
Connection con;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connection established");
}
catch(Exception e)
{
System.out.println("Connection error");
}
try
{
String str="jdbc.odbc:dsn1";
con=DriverManager.getConnection(str,"","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select*from employee");
int n=rs.getMetaData().getColumnCount();
for(int i=1;i<=n;i++)
{
System.out.print(rs.getMetaData().getColumnLabel(i)+'t');
System.out.println("");
while(rs.next())
{
for(int i=1;i<=n;i++)
{
System.out.print(rs.getString(i)+'t');
}
System.out.println("");
}
rs.close();
con.close();
}
catch(SQLException e)
{
System.out.print("SQL error");
}
}
}
A. missing }
B. missing {
C. missing semicolon
D. missing package statement
Answer: A

23. Consider the following program and identify the missing statement.
class Type4_simple
{ public static void main(String[] args)
{try
{ Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@pearl:1521:oracle10g";
Connection conn = DriverManager.getConnection(url,"java","java");
System.out.println("successfully connected");
}
catch(Exception e){e.printStackTrace()}
}
}
A. Missing package statement
B. Missing semicolon & Package Statement
C. Missing initialization
D. Missing semicolon
Answer: B

24. Consider the following program What should be the correction done in the program to get
the correct output?
import java.sql.*
class ExecuteQueryTest
{
public static void main(String args[])
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
String url="jdbc:odbc:xyz";
Connection con = DriverManager.getConnection(url);
Statement state =con.createStatement();
System.out.println("Statement object created");
String sql= "select Name,Age from student";
ResultSet rs =state.executeQuery(sql);
String text = " ";
while (rs.next())
{
text+= rs.getString(1) + " " + rs .getInt (2) + 'n' ;
}
System.out.println(text);
}
catch(Exception e)
{ System.out.println(“error”); }
}
}

A. missing JDBC driver


B. missing semicolon
C. missing statement
D. missing prepareStatement
Answer: B

25. Consider the following program, it has 10 Records in the Table. What will be the output of
following Code?
import java.sql.*;
public class db15
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:DSN2","","");
Statement s=c.createStatement( );
int n=s.executeUpdate("update table set name='Ramesh'");
ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"t"+"Roll no"+"t"+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+"t"+rs.getInt(2)+"t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. Ramesh name will be given only for 1st Record
B. The query will not be processed
C. Ramesh name will be given to all the records
D. None Of Above
Answer: A

26. Consider the following program.


What should be the correction done in the program to get correct output?
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " t " + "Roll_No" + " t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" t "+rs.getInt(2)+" t t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. Missing Semicolon
B. Missing {
C. Missing }
D. Missing package statement
Answer: D

27. Consider the following program.


What should be the correction done in the program to get correct output?
public class displayemployee
{
public static void main(String[] args);
{
Connection con;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connection established");
}
catch(Exception e)
{
System.out.println("Connection error");
}
try
{
String str="jdbc.odbc:dsn1";
con=DriverManager(str,"","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select*from employee");
int n=rs.getMetaData().getColumnCount();
for(int i=1;i<=n;i++)
{
System.out.print(rs.getMetaData().getColumnLabel(i)+'t');
}
System.out.println("");
while(rs.next())
{
for(int i=1;i<=n;i++)
{
System.out.print(rs.getString(i)+'t');
}
System.out.println("");
}
rs.close();
con.close();
}
catch(SQLException e)
{
System.out.print("SQL error");
}
}
}
A. missing getConnection() method
B. error in main()
C. missing package statement
D. all of the above
Answer: D

28. Consider the following program. What should be the correction done to get correct output?
import java.sql.*;
class DBEx
{
public static void main(String args[])
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:mydsn","","");
Statement s =
c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
s.executeUpdate("insert into Student values(8,'H','FYCO')");
c.close();
}catch(Exception e)
{
System.out.println("Exception generated: "+e);
}
}
}
A. Use executeQuery() method instead of executeUpdate() method
B. Use executeInsert() method instead of executeUpdate() method
C. Use executeNewRow() method instead of executeUpdate() method
D. No correction is required
Answer: D

29. Consider the following program.Find out the output?


import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
PreparedStatement s=c.prepareStatement("insert into student values (?,?));
s.setString(1,"Riya");
s.setString(2,17);
int i=s.executeUpdate();
System.out.println("Record Updated");
s.close();
c.close();
}
}
A. Riya will be inserted in first column and 17 will be inserted in second column
B. 17 will be inserted in first column and Riya will be inserted in second column
C. only 17 will be inserted in second column
D. only Riya will be inserted in first column
Answer: A

30. Consider the following program.Select the interface to fill in the blank space.
import java.sql.*;
public class Column
{
public static void main(String[] args)
{

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:xyz";
Connection con = DriverManager.getConnection(url);
try
{
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM Account");
.............................. md = rs.getMetaData();
int col = md.getColumnCount();
System.out.println("Number of Column : "+ col);
System.out.println("Columns Name: ");
for (int i = 1; i <= col; i++)
{
String col_name = md.getColumnName(i);
System.out.println(col_name);
}
}
catch (SQLException s)
{
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e)
{
System.out.println("error");
}
}
}
A. ResultSet
B. ResultSetMetaData
C. MetaData
D. PreparedStatement
Answer: B

31. Consider the following program.What shoud be added to the program to get the correct
output.
import java.sql.*;

public class Prepare_Demo


{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:DATA");
PreparedStatement ps = con.prepareStatement("insert into User
(ID,Name1,City,Age)values(?,?,?,?)");
ps.setInt(1,20);
ps.setString(2, "Abc");
ps.setInt(4,31);
ps.setString(3, "Pune");
System.out.println("inserted");
con.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
A. ps.executeQuery();
B. ps.executeUpdate();
C. ps.execute();
D. ps.executeInsert();
Answer: B

32. Consider the following program.What should be the correction done in the program to get
correct output?
import java.sql.*;
public class InsertPre
{
public static void main(String args[])
{
String url = "jdbc:odbc:xyz";
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url);
String sql ="insert into Account(Acc_No,Acc_Type,Ammount) values(?,?)";
pst = con.prepareStatement(sql);
pst.setInt(1, 15);
pst.setString(2, "saving");
pst.setInt(3, 30000);
pst.executeUpdate();
pst.close();
sql = "select * from Account";
pst = con.prepareStatement(sql);
rs = pst.executeQuery();
while (rs.next())
{
System.out.print(rs.getInt(1) + "t");
System.out.print(rs.getString(2) + "t");
System.out.println(rs.getInt(3));
}
rs.close();
pst.close();
con.close();
}
catch (Exception e)
{
}
}
}
A. Error in main()
B. Error in close()
C. Error in loop
D. Error in Query
Answer: D

33. Consider the following programe & find the error statement.
import java.sql.*;
class Test{
public static void main(String ar[]){
try{
String url="jdbc:odbc:mydsn";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection(url);

ResultSet rs=st.executeQuery("select * from login");

while(rs.next()){
System.out.println(rs.getString(1));
}
}catch(Exception ee){System.out.println(ee);}
}
}
A. Connecction not established.
B. Missing Statement st=c.createStatement();
C. Other Error
D. Successfully Run
Answer: B

34. Fill in the blank.


import java.sql.*;
import sun.jdbc.odbc.*;
public class DatabaseDemo {
public static void main(String[] args) throws Exception {
Driver d = new JdbcOdbcDriver();
DriverManager.registerDriver(d);
Connection con = DriverManager.getConnection("jdbc:odbc:mydsn");
____________ = con.getMetaData();
con.close();
}
A. ResultSetMetaData metadata
B. DatabaseMetaData metadata
C. Statement stmt;
D. PreparedStatement stmt;
Answer: B

35. Find the error of following code


import java.sql.*;

public class dbAccess


{
public static void main(String[] args)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:ab", "", "");
Statement s = conn.createStatement();
String s1="insert into Table1 values('akash','201')";
s.executeUpdate(s1);
s.close();
conn.close();
}
}
A. line no4 JDBC driver not loaded properly
B. no error data inser into database
C. class not found exception Class.forName must be catch or thrown exception
D. sql package not imported properly
Answer: Try and Catch block missing.

36. Find the missing method in following code.


class jdbc1
{
public static void main(String ar[])throws Exception
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:oradsn;UID=scott;PWD=tiger");
Statement st=con.---------------------
ResultSet rs=st.executeQuery("select * from emp");
while(rs.next())
{
int pid=rs.getInt(1);
String nm=rs.getString(2);
System.out.println("nProduct ID="+pid+"nProduct Name="+nm+"n");
}
con.close();
}
A. createStatement()
B. CreateStatement()
C. createStatement();
D. none of these
Answer: C
37. What is the correction in the following code to get the output
import java.io.IOException;
import java.sql.*;
public class contest {
public void main(String args[])throws IOException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("n Drivers are properly Loded");
String url="jdbc:odbc:abc"
Connection con=DriverManager.getConnection(url);
System.out.println("connetion establised");
con.close();
}catch(SQLException e){} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } }
A. Missing Semicolon
B. Missing {
C. Missing }
D. missing statement
Answer: A

38. import java.sql.*;


class InsertPrepared{
public static void main(String args[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement stmt=con.prepareStatement("insert into Emp values(?,?)");
stmt.setInt(1,101);//1 specifies the first parameter in the query
stmt.setString(2,"Ratan");
int i=stmt.executeUpdate();
System.out.println(i+" records inserted");
con.close();
}catch(Exception e){ System.out.println(e);}
} }
A. Error
B. 101 is inserted at first index position and Ratan is inserted at second index position into
Emp
C. both a and b
D. None of the above
Answer: B

39. import java.sql.*;


import sun.jdbc.odbc.*;
class mydatabase
{
public static void main(String args[]) throws SQLException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mydsn");
PreparedStatement pstmt=con.prepareStatement("update student set branch=? where
branch=?");
pstmt.setString(1,"CO");
pstmt.setString(2,"CM");
stmt.executeUpdate();
con.close();
System.out.println("record updated...");
}
}
A. this program will not change branch codes of all students from 'CO' to 'CM'.
B. this program will change table name of student from 'CM' to 'CO'.
C. this program will change column name of student table from 'CM' to 'CO'.
D. this program will change branch codes of all students from 'CO' to 'CM'.
Answer: D

40. import java.sql.*;


public class Pstatement
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement st=con.createStatement();
String a="Update emp set name1=_______ where id=____________";
PreparedStatement ps=con.prepareStatement(a);
ps.setString(1,"aaa");
ps.setInt(2,4);
ps.executeUpdate();
ResultSet rs=st.executeQuery("select * from emp");
System.out.println(" id"+" salary"+" name");
while(rs.next())
{
System.out.println(" "+rs.getInt("id")+" "+rs.getString("salary")+
" "+rs.getString("name1"));
}
con.close();
}
catch(SQLException e)
{}
catch(Exception e)
{}
} }
A. *,*
B. $,$
C. ?,?
D. &,&
Answer: C
41. In following Java program fill statement showing _______________________.Select any one
option from given options
import java.sql.*;
class Testdemo
{
public static void main(String srgs[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
String url="jdbc:odbc:info";
Connection con=DriverManager.getConnection(url);
System.out.println("connection to database created");
Statement smt=con.createStatement();
System.out.println("Statement object created");
String sql="Select Name,Age from Amol";
ResultSet result=smt._______________________
String text="";
while(result.next());
{
text +result.getString(1)+""+results.getInt(2)+'n';
}
System.out.println(text);
}
catch(sQLException e)
{
System.out.pritln("SQL error");
}
catch(Exceptionn e)
{
System.out.println("error");
}
A. createStatement();
B. executeQuery(sql);
C. getConnection()
D. None of these
Answer: B

42. Observe the following code and what will be the output of the program
import java.sql.*;
import java.io.*;
public class Resultset1
{
public static void main(String a[])
{
String s1;
int cnt=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers are properly loded");
String url="jdbc:odbc:abc";
Connection con= DriverManager.getConnection(url);
System.out.println("Connection Sucessful");
s1="Select Comp_name,num,cost,capacity from company order by num";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery (s1);
rs= st.getResultSet();
ResultSetMetaData rsmd= rs.getMetaData();
System.out.println("Total COLOUNMS ="+ rsmd.getColumnCount());
System.out.println("Column no 1 is = " +rsmd.getColumnName(1));
System.out.println("Column no 1 data type is = " + rsmd.getColumnTypeName(1));
System.out.println("Name of table = "+rsmd.getTableName(1));
con.close();
}
catch(SQLException e)
System.out.println("SQL Error...!!!");
}
catch(Exception e)
{
System.out.println("Error Connection Un-sucessful...!!!");
}
}
}
A. The output will give information about rows and coloums
B. The output will give information about ResultSet Metadata
C. The output will give information about database
D. The output will give information about ResultSet table
Answer: B

43. Observer the following program.


import java.sql.*;
class TYIFCon{
public static void main(String args[]){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:empdsn");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeUpdate("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
A. In This program executeUpdate() must be replaced by executeQuery()
B. In This program executeUpdate() must be replaced by executeQueryUpdate()
C. In This program executeUpdate() must be replaced by executeUpdateQuery()
D. none of the above
Answer: A

44. Output of the following program


import java.sql.*;
Class ExecuteUpdateTest
{
public static void main(String argu[])
{
try
{
int I;
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
System.out.println(“Driver Loaded”);
String url=”jdbc:odbc:xyz”;
Connection con=DriverManager.getConnection(url);
System.out.println(“Connection to database created”);
Statement state=con.createStatement();
System.out.println(“Statement object created”);
String sql=”Insert into tanni values(‘Tanmy’,2)”;
I=state.executeUpdate(sql);
System.out.println(“Record inserted ”+i);
String sql1=”Insert into tanni values(‘Raddhi’,2)”;
I=state.executeUpdate(sql1);
System.out.println(“Record inserted”+i);
String sql2=”Insert into tanni values(‘Siddi’,2)”;
I=state.executeUpdate(sql2);
System.out.println(“Record inserted”+i);
}
catch(SQLException e)
{
System.out.println(“SQL error”);
}
catch(Exception e){
System.out.println(“SQL error”);
}
}
}
A. Driver loaded
Connection to database created
Statement object created
Record inserted 1
Record Inserted 2
Record Inserted 3

B. Driver loaded
Record inserted 1
Record Inserted 2
Connection to database created
Statement object created
Record Inserted 3

C. Record inserted 1
Record Inserted 2
Connection to database created
Driver loaded
Statement object created
Record Inserted 3

D. Connection to database created


Driver loaded
Record inserted 1
Record Inserted 2
Statement object created
Record Inserted 3
Answer: A

45. Select Correct code for given output

A. import java.io.*;
public class EmployeeTableUpdate
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String URL = "jdbc:odbc:EmployeeDatabase";
Connection con = DriverManager.getConnection(URL);
System.out.println("Connection to database created.");
String sql = "update Employee set Name=? where Name=?";
PreparedStatement state = con.prepareStatement(sql);
System.out.println("PreparedStatement Object Created.");

state.setString(1, "Ram");
state.setString(2, "Ramesh");
state.executeUpdate();
System.out.println("Entry Updated.");
System.out.println("Contents Of Database After Updating");
System.out.println("NAMEtAGE");
sql = "select * from Employee";
state = con.prepareStatement(sql);
ResultSet results = state.updateQuery();
String text = "" ;
while(results.next())
{
text += results.getString(1) + "t" + results.getInt(2) + "n";
}
System.out.println(text);
state.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
} } }

B. mport java.sql.*;
public class EmployeeTableUpdate
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String URL = "jdbc:odbc:EmployeeDatabase";
Connection con = DriverManager.getConnection(URL);
System.out.println("Connection to database created.");
String sql = "update Employee set Name=? where Name=?";
Statement state = con.createStatement(sql);
System.out.println("PreparedStatement Object Created.");
state.setString(1, "Ram");
state.setString(2, "Ramesh");
state.executeUpdate();
System.out.println("Entry Updated.");
System.out.println("Contents Of Database After Updating");
System.out.println("NAMEtAGE");
sql = "select * from Employee";
state = con.Statement(sql);
ResultSet results = state.executeQuery();
String text = "" ;
while(results.next())
{
text += results.getString(1) + "t" + results.getInt(2) + "n";
}
System.out.println(text);
state.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

C. import java.sql.*;
public class EmployeeTableUpdate
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String URL = "jdbc:odbc:EmployeeDatabase";
Connection con = DriverManager.getConnection(URL);
System.out.println("Connection to database created.");
String sql = "update Employee set Name=? where Name=?";
PreparedStatement state = con.prepareStatement(sql);
System.out.println("PreparedStatement Object Created.");
state.setString(1, "Ram");
state.setString(2, "Ramesh");
state.executeUpdate();
System.out.println("Entry Updated.");
System.out.println("Contents Of Database After Updating");
System.out.println("NAMEtAGE");
sql = "select * from Employee";
state = con.prepareStatement(sql);
ResultSet results = state.executeQuery();
String text = "" ;
while(results.next())
{
text += results.getString(1) + "t" + results.getInt(2) + "n";
}
System.out.println(text);
state.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
} } }

D. import java.sql.*;
public class EmployeeTableUpdate
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
Connection con = DriverManager.getConnection(URL);
System.out.println("Connection to database created.");
String sql = "update Employee set Name=? where Name=?";
PreparedStatement state = con.prepareStatement(sql);
System.out.println("PreparedStatement Object Created.");
state.setString(1, "Ram");
state.setString(2, "Ramesh");
state.executeUpdate();
System.out.println("Entry Updated.");
System.out.println("Contents Of Database After Updating");
System.out.println("NAMEtAGE");
sql = "select * from Employee";
state = con.prepareStatement(sql);
ResultSet results = state.executeQuery();
String text = "" ;
while(results.next())
{
text += results.getString(1) + "t" + results.getInt(2) + "n";
}
System.out.println(text);
state.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
} } }
Answer: C

46. Select proper code for given output

A.
import java.sql.*;
public class MyDB1
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN");
PreparedStatement ps=c.prepareStatement( "insert into Student values(?,?,?)");
int count= ps.executeUpdate();
System.out.println("Data inserted"+count);
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select * from Student");
System.out.println("tName"+"tt"+"Roll no"+"tt"+"Avg n");
while(rs.next())
{
System.out.println("t"+rs.getString(1)+"tt"+rs.getInt(2)+"tt"+rs.getInt(3));
}
s.close();
c.close();
}
}

B.
import java.sql.*;
public class MyDB1
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN");
PreparedStatement ps=c.prepareStatement( "insert into Student values(?,?,?)");
ps.setString(1,args[0]);
ps.setString(2,args[1]);
ps.setString(3,args[2]);
int count= ps.executeUpdate();
System.out.println("Data inserted"+count);
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select* from Student");
System.out.println("tName"+"tt"+"Roll no"+"tt"+"Avg n");
while(rs.next())
{
System.out.println("t"+rs.getString(1)+"tt"+rs.getInt(2)+"tt"+rs.getInt(3));
}
s.close();
c.close();
}
}

C.
import java.sql.*;
public class MyDB1
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN");
PreparedStatement ps=c.prepareStatement( "insert into Student values(?,?,?)");
ps.setString(1,args[0]);
ps.setString(2,args[1]);
ps.setString(3,args[2]);
int count= ps.executeUpdate();
System.out.println("Data inserted"+count);
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("delete * from Student");
System.out.println("tName"+"tt"+"Roll no"+"tt"+"Avg n");
while(rs.next())
{
System.out.println("t"+rs.getString(1)+"tt"+rs.getInt(2)+"tt"+rs.getInt(3));
}
s.close();
c.close();
}
}

D.
import java.sql.*;
public class MyDB1
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN");
String a= "insert into Student values(?,?,?)"
PreparedStatement ps=c.prepareStatement();
ps.setString(1,args[0]);
ps.setString(2,args[1]);
ps.setString(3,args[2]);
int count= ps.executeUpdate(a);
System.out.println("Data inserted"+count);
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select* from Student");
System.out.println("tName"+"tt"+"Roll no"+"tt"+"Avg n");
while(rs.next())
{
System.out.println("t"+rs.getString(1)+"tt"+rs.getInt(2)+"tt"+rs.getInt(3));
}
s.close();
c.close();
}
}
Answer: B

47. Select the correct code to insert record to the stud_table


A. import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
Statement st=con.createStatement();
sql="insert into stud_table values (1,'ramesh','pune')";
Object msg=st.execute(sql);
System.out.print(msg);
st.close();
}
}

B. import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
Statement st=con.createStatement();
sql="insert into stud_table (roll,name,city) values (1,'ramesh','pune')";
Object msg=st.execute(sql);
System.out.print(msg);
st.close();
}
}
C. Both A & B
D. none of the above
Answer: D

48. Select the missing statement in the program


import java.sql.*;
import java.io.*;
public class JDBCDemo
{
public static void main(String args[])
{
try
{
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from Student");
System.out.println("Name ttRollNumber tt Percentage");
while(rs.next())
{
System.out.println(rs.getString(1) + "tt" + rs.getString(2) + "ttt" + rs.getString(3));
}
rs.close();
st.close();
con.close();
}
catch(Exception e)
{ e.printStackTrace();
}}}

A. Class.forName("JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:IIT");
B. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:IIT");
C. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = con.getConnection("jdbc:odbc:IIT");
D. forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager("jdbc:odbc:IIT");
Answer: B

49. Select the statement that must be added to the following program to get the correct output.
import java.sql.*;
import java.io.*;
class DisTable1
{
public static void main(String args[])
{
int id=0;
String name="",addr="";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:mydsn");
Preparedstatement pst=cn.prepareStatement("select * from emp");
System.out.println("EmpIdt"+"Namet"+"Address");
while(rs.next())
{
System.out.print(rs.getInt(1)+"t");
System.out.print(rs.getString(2)+"t");
System.out.print(rs.getString(3)+"n");
}
cn.close();
}catch(Exception e){}
}
}
A. ResultSet rs=pst.executeQuery();
B. Resultset rs=pst.ExecuteQuery();
C. Connection con=DriverManager.getConnection("jdbc:odbc:mydsn","","");
D. None of these
Answer: A

50. Select the statement that should be added to program to get corrected output
import java.sql.*;
import java.io.*;
class Jdbc_ResultSet
{
public static void main(String arg[])
{
String s1;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers loaded");
String url="jdbc:odbc:abc";
Connection con=DriverManager.getConnection(url);
System.out.println("connection established");
s1="select comp_name,num,cost,capacity from company order by num";
Statement st=con.createStatement();
rs=st.getResultSet();
System.out.println("Comp_name"+" "+"num"+" "+"cost"+ " "+"capacity");
System.out.println();
while(rs.next())
{
System.out.println(rs.getString("comp_name")+" "+rs.getInt("num")+" "+rs.getInt("cost")+"
"+rs.getString("capacity"));
}
con.close();
}
catch(SQLException e)
{
System.out.println(" sql error");
}
catch(Exception e)
{
System.out.println(" connection error1");
}
}
}
A. st.close()
B. rs.createStatement()
C. ResultSet rs=st.executeQuery(s1);
D. st.executeUpdate(s1);
Answer: C

51. To delete reord from database table student what modification we have to do in following
program.
import java.sql.*;
public class JdbcDemo1 {
public static void main(String args[]) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mydsn");
Statement stmt = con.createStatement();
int result=st.executeUpdate("delete student where id=1");
System.out.println(result+" records affected");
con.close();
}}
A. int result=("delete from student where id=1");
B. stmt.executeUpdate("delete from student ");
C. int result=stmt.executeUpdate("delete from student where id=1");
D. int result=st.executeUpdate("delete from student where id=1");
Answer: C

52. To display ID, NAME and SALARY of a customer whose salary is greater than 2000 AND age is
less tan 25 years from the CUSTOMERS table, fill the correct query statement in the
********* in the following code. Consider CUSTOMER table with 5 fields such as (ID, NAME,
AGE, ADDRESS, SALARY )
import java.sql.*;
class DeleteAllRecord
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:xyz");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("************");
where(rs.next())
{
System.out.println(rs.getInt(1)+"t"+rs.getString(2)+"t"+rs.getInt(3))
}
con.close();
}
}
A. SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000 AND AGE < 25
B. SELECT * FROM CUSTOMERS WHERE SALARY > 2000 AND AGE < 25
C. SELECT ID, NAME, SALARY FROM CUSTOMERS WHOSE SALARY > 2000 AND AGE < 25
D. SELECT ID, NAME, SALARY FROM CUSTOMERS TABLE WHERE SALARY > 2000 AND AGE <
25
Answer: A

53. To to get the column names and row data from a table. Select the proper statement from the
following AT *____________line
import java.sql.*;
public class SelDemo
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odb c: myDSN ");
Statement st = con.createStatement();
*_________________________________//(Choose correct option for this line)
while(sel.next())
{
String name = sel.getString(1);
String pass = sel.getString(2);
System.out.println(name+" "+pass);
}
}
catch(Exception e)
{
System.out.println("Errooorrrr"+e.getMessage());
}
}
}
A. ResultSet sel = st.executeQuery ("select * from Login");
B. ResultSet sel = con.executeQuery ("select * from Login");
C. ResultSet con = sel.executeQuery ("select * from Login");
D. none of the above
Answer: A

54. try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException cnfe)
{
System.err.println("Error loading driver: " + cnfe);
}
A. Will load two different drivers
B. Will load only one drivers
C. Will throw error object
D. None of the above
Answer: A

55. What correction should be done in the program to get corrected output
import java.sql.*;
import java.io.*;
class JdbcP
{
public static void main(String arg[])
{
try
{
DataInputStream in=new DataInputStream(System.in);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers loaded");
String url="jdbc.odbc.abc";
Connection con=DriverManager.getConnection(url);
System.out.println("connection established");
PreparedStatement ps=con.prepareStatement("create table movie6(num Integer,mvnm
Varchar(30))");
ps.executeUpdate();
System.out.println("Table Created");
String sql="insert into movie6 VALUES(?,?)";
PreparedStatement ps2=con.prepareStatement(sql);
System.out.println("Enter movie code");
int mcd=Integer.parseInt(in.readLine());
ps2.setInt(1,mcd);
System.out.println("Enter movie name");
String name=in.readLine();
ps2.setString(2,name);
ps2.executeUpdate();
con.close();
}
catch(SQLException e)
{
System.out.println(" sql error");
}
catch(Exception e)
{
System.out.println(" connection error1");
}
}
}
A. Class.forName("sun.jdbc.odbc.JdbcOdbcDriverManger");
B. Class.forName("sun:jdbc:odbc:JdbcOdbcDriver");
C. String url="jdbc:jdbcodbcDriver:abc";
D. String url="jdbc:odbc:abc";
Answer: D

56. What happens if the following code is executed?


import java.sql.*;
public class S1Q57{
public static void main(String[] args) {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:shree");
Statement stm = con.createstatement();
String query ="select rollno,name,percent from student ";
ResultSet rs = stm.executeQuery(query);
while(rs.next()){
System.out.println("Roll No = "+rs.getInt(1));
System.out.println("Name = "+rs.getString(2));
System.out.println("per = "+rs.getDouble(3));
}
con.close();
}
}
A. There is a compiler error
B. There is a run time error
C. Program run Successfully and print the content of table
D. Retrieval of the fields is in the wrong order
Answer: A

57. import java.sql.*;


public class execute
{
public static void main(String args[])
{
try
{
String url="jdbc:odbc:abcd";
Connection con=DriverManager.getConnection(url);
System.out.println("Connection Established");
String sql="insert into student values(11,'Ramesh')";
Statement st=con.createStatement();
st.executeUpdate(sql);

System.out.println("Data Inserted");

con.close();
}
catch(SQLException e)
{
System.out.println("SQL Error Has Occured");

}
catch(Exception e)
{
System.out.println("Error");
}
}
}
A. to register the driver
B. to create the connection with database
C. to close the connection
D. None of above
Answer: A

58. What is the output of following program:


import java.sql.*;
class exp10_5
{
public static void main(String m[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dsnname");
Statement cmd=con.createStatement();
rs=cmd.executeQuery("select * from tabel1");
while(rs.next())
{
System.out.println(rs.getInt(1)+""+rs.getInt(2)+""+rs.getString(3));
}
cmd.close();
con.close();
}
}
A. Compile Error
B. Runtime Error
C. It prints all data from table
D. None of these
Answer: A

59. What should be the correction done in the following program to get correct output?
import java.sql.*;
import java.io.*;
class DemoInsert
{
public static void main(String args[])
{
int u=0;
try
{
Class.ForName("sun.jdbc.odbc.JdbcOdbcDriver");
String myURL="jdbc:odbc:MyDSN";
Connection con=DriverManager.getConnection(myURL);
Statement st=con.createStatement();
c=st.executeUpdate("insert into student values(1,50)");
if(u!=0)
System.out.println("Record inserted");
else
System.out.println("Record NOT inserted");
con.close();
}catch(Exception e){}
}
}
A. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
B. Class.Forname("sun.jdbc.odbc.JdbcOdbcDriver");
C. Class.forName("sun.jdbc.odbc.jdbcodbcDriver");
D. Missing ;
Answer: A

60. What will be the output of following code?


import java.sql.*;
public class JdbcGetConnection {
public static void main(String args[]) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/komal", "root", "root");
System.out.println("Connection is closed : " + con.isClosed());
con.close();
System.out.println("Connection is closed : " + con.isClosed());
} catch (Exception e) {
System.out.println(e);
} } }
A. Connection is closed : false, Connection is closed : true
B. Connection is closed : true
C. Connection is closed : true, Connection is closed : true
D. Connection is closed : false, Connection is closed : false
Answer: A

61. Which is the correct method for updating table rows from given option.
import java.sql.*;
public class Updatedbase
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp");
St.********("Update emp set name1='jack' where id=2");
System.out.println("nnafter change");
rs=st.executeQuery("select * from emp");
while(rs.next())
{
System.out.println("id:"+rs.getInt("id"));
System.out.println("salary:"+rs.getString("salary"));
}
con.close();
}
catch(SQLException e){}
catch(Exception e)
{ }
} }
A. executeUpdate()
B. executeQuery()
C. execute()
D. ExecuteUpdate()
Answer: A

62. Which of the following program used to delete single row from table student having ID=15 in
following table using prepareStatement method?

A.
import java.sql.*;
class ConDemo5
{
public static void main(String a[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:samarth");
PreparedStatement ps=con.prepareStatement();
ps.executeUpdate("delete from student where ID=15");
ps.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
} } }

B.
import java.sql.*;
class ConDemo5
{
public static void main(String a[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:samarth");
PreparedStatement ps=con.prepareStatement();
ps.executeUpdate("delete from student where ID=?");
close();
close();
}
catch(Exception e)
{
System.out.println(e);
} } }

C.
import java.sql.*;
class ConDemo5
{
public static void main(String a[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:samarth");
PreparedStatement ps=con.prepareStatement("delete from student where ID=?");
ps.setInt(1,15);
ps.executeQuery();
ps.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
} } }

D.
import java.sql.*;
class ConDemo5
{
public static void main(String a[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:samarth");
PreparedStatement ps=con.prepareStatement("delete from student where ID=?");
ps.setInt(1,15);
ps.executeUpdate();
ps.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
} } }
Answer: D

63. Which of the missing code need to be inserted in a given code to delete second row in
ResultSet.
import java.sql.*;
import java.sql.ResultSet.*;
class delrset
{public static void main(String args[])
{try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:stud");
Statement s =
con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=s.executeQuery("select * from stud");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
System.out.println("After deleting row:");
rs.first();
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
while(rs.next())
{System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
}
con.close();
}
catch(Exception e){ }
}
}

A. rs.next( )
rs.delete();

B. rs.first();
rs.next( )
rs.delete();

C. rs.first( );
rs.next( )
rs.deleterow();

D. rs.absolute(2);
rs.deleteRow();
Answer: D

64. Which ONE of the following is missing statement in the program below?
import java.sql.*;
class ExecuteQueryTest
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
String url="jdbc:odbc:aditya";
Connection con = DriverManager.getConnection(url);
System.out.println("connection to database created");
Statement st = con.createStatement();
System.out.println("Statement object created");
String sql="select Name,Age from tanni";
ResultSet results = state.executeQuery(sql);
String text=" ";
while()
{
text +=results.getString(1)+ "" +results .getInt (2)+ 'n';
}
System.out.println(text);
}
catch(SQLException e)
{
System.out.println("SQL error");
}
catch(Exception e)
{
System.out.println("error");
} } }
A. state.results()
B. results.next()
C. next.results()
D. results()
Answer: B

65. Which statement required for getting proper output


import java.sql.*;
public class updatevalues1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:db");
String sql="update StudTable set Name=? where Rollno=2";
String Name="Ram";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,Name);
----------------------------------------- ;
System.out.println("Record Updated.................");
con.close();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException se)
{
se.printStackTrace();
}
}
}
A. ps.execute();
B. ps.executeUpdate()
C. ps.executeQuery()
D. None of the above
Answer: B

66. Which statements are needed to establish connection to database?


A.
1) Register the driver class
2) Create the connection object
3) Create the Statement object
4) Execute the query
5) Close the connection object
B.
1) Register the driver class
2) Create the connection object
3) Create the Statement object
4) Execute the query
C.
1) Register the driver class
2) Create the connection object
3) Create the Statement object
4) Close the connection object
D.
1) Register the driver class
2) Create the connection object
3) Close the connection object
Answer: A

67. Which statements are required in following program to retrive records from table
import java.sql.*;
public class JDBCExample {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(jdbc:odbc:stud”);
System.out.println(" Records of table...");
stmt = conn.createStatement();
______________________________________________________
__________________________________________________________________
System.out.println("Inserted records into the table...");
System.out.println("Goodbye!");
}}
A. ResultSet rs=stmt.executeQuery("select * from student");
B. ResultSet rs=stmt.executeUpdate("select * from student");
C. ResultSet rs=stmt.execute("select from student");
D. None of these
Answer A

68. Which statements are used to display the contents of table?


import java.sql.*;

public class jdbcResultSet {


public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.jdbcodbcDriver");
}
catch(ClassNotFoundException e) {
System.out.println("Class not found "+ e);
}
try {
Connection con = DriverManager.getConnection
("jdbc:derby://localhost:1527/testDb","username",
"password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery
("SELECT * FROM employee");
System.out.println("id name job");
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
String job = rs.getString("job");
System.out.println(id+" "+name+" "+job);
}
}
catch(SQLException e){
System.out.println("SQL exception occured" + e);
}
}
}
A. getInt & executeQuery methods
B. getString, & executeQuery methods
C. getString,getInt & executeQuery methods
D. getString,getInt methods
Answer: D

69. Write the missing statement?


import java.sql.*;
class Rsmd{
public static void main(String args[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement ps=con.prepareStatement("select * from emp");
ResultSet rs=ps.executeQuery();
---------------------------------------------------
System.out.println("Total columns: "+rsmd.getColumnCount());
System.out.println("Column Name of 1st column: "+rsmd.getColumnName(1));
System.out.println("Column Type Name of 1st column: "+rsmd.getColumnTypeName(1));
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
A. ResultSetMetaData rsmd=getMetaData();
B. ResultSetMetaData =rs.getMetaData();
C. ResultSetMetaData rsmd=rs.getMetaData();
D. None of above
Answer: C

You might also like