50 TOP Real Time JDBC multiple choice questions and answers PDF

Read the most frequently asked 50 top JDBC multiple choice questions and answers PDF for freshers and experienced

JDBC Objective type Questions and Answers List


1. Which statements about JDBC are true?
a. JDBC is an API to connect to relational-, object- and XML data sources
b. JDBC stands for Java DataBase Connectivity
c. JDBC is an API to access relational databases, spreadsheets and flat files
d. JDBC is an API to bridge the object-relational mismatch between OO programs and relational
databases
Ans: b,c

2. Which packages contain the JDBC classes?
a. java.jdbc and javax.jdbc
b. java.jdbc and java.jdbc.sql
c. java.sql and javax.sql
d. java.rdb and javax.rdb
Ans:c

3. Which type of driver provides JDBC access via one or more ODBC drivers?
a. Type 1 driver
b. Type 2 driver
c. Type 3 driver
d. Type 4 driver
Ans: a

4. Which type of driver converts JDBC calls into the network protocol used by the database management system directly?
a. Type 1 driver
b. Type 2 driver
c. Type 3 driver
d. Type 4 driver
Ans: d

5. Which type of Statement can execute parameterized queries?
a. PreparedStatement
b. ParameterizedStatement
c. ParameterizedStatement and CallableStatement
d. All kinds of Statements (i.e. which implement a sub interface of Statement)
Ans: a

6. How can you retrieve information from a ResultSet?
a. By invoking the method get(…, String type) on the ResultSet, where type is the database type
b. By invoking the method get(…, Type type) on the ResultSet, where Type is an object which represents a database type
c. By invoking the method getValue(…), and cast the result to the desired Java type.
d. By invoking the special getter methods on the ResultSet: getString(…), getBoolean (…), getClob(…),…
Ans: d

7. How can you execute DML statements (i.e. insert, delete, update) in the database?
a. By making use of the InsertStatement, DeleteStatement or UpdateStatement classes
b. By invoking the execute(…) or executeUpdate(…) method of a normal Statement object or a sub-interface object thereof
c. By invoking the executeInsert(…), executeDelete(…) or executeUpdate(…) methods of the DataModificationStatement object
d. By making use of the execute(…) statement of the DataModificationStatement object
Ans: b

8. How do you know in your Java program that a SQL warning is generated as a result of executing a SQL statement in the database?
a. You must catch the checked SQLException which is thrown by the method which executes the statement
b. You must catch the unchecked SQLWarningException which is thrown by the method which executes the statement
c. You must invoke the getWarnings() method on the Statement object (or a sub interface thereof)
d. You must query the ResultSet object about possible warnings generated by the database
Ans: c

9. What is, in terms of JDBC, a DataSource?
a. A DataSource is the basic service for managing a set of JDBC drivers
b. A DataSource is the Java representation of a physical data source
c. A DataSource is a registry point for JNDI-services
d. A DataSource is a factory of connections to a physical data source
Ans: d

10. What is the meaning of ResultSet.TYPE_SCROLL_INSENSITIVE
a. This means that the ResultSet is insensitive to scrolling
b. This means that the Resultset is sensitive to scrolling, but insensitive to updates, i.e. not updateable
c. This means that the ResultSet is sensitive to scrolling, but insensitive to changes made by others
d. The meaning depends on the type of data source, and the type and version of the driver you use with this data source
Ans: c

11. Are ResultSets updateable?
a. Yes, but only if you call the method openCursor() on the ResultSet, and if the driver and database support this option
b. Yes, but only if you indicate a concurrency strategy when executing the statement, and if the driver and database support this option
c. Yes, but only if the ResultSet is an object of class UpdateableResultSet, and if the driver and database support thisoption
d. No, ResultSets are never updateable. You must explicitly execute DML statements (i.e. insert, delete and update) to change the data in the underlying database
Ans: b

12. What statements are correct about JDBC transactions (2 correct answers)?
a. A transaction is a set of successfully executed statements in the database
b. A transaction is finished when commit() or rollback() is called on the Connection object,
c. A transaction is finished when commit() or rollback() is called on the Transaction object
d. A transaction is finished when close() is called on the Connection object.
Ans: d

13. How can you start a database transaction in the database?
a. By asking a Transaction object to your Connection, and calling the method begin() on it
b. By asking a Transaction object to your Connection, and setting the autoCommit property of the Transaction to false
c. By calling the method beginTransaction() on the Connection object
d. By setting the autoCommit property of the Connection to false, and execute a statement in the database
Ans:d

14. What is the meaning of the transaction isolation level TRANSACTION_REPEATABLE_READ
a. Dirty reads, non-repeatable reads and phantom reads can occur
b. Dirty reads are prevented; non-repeatable reads and phantom reads can occur
c. Dirty reads and non-repeatable reads are prevented; phantom reads can occur
d. Dirty reads, non-repeatable reads and phantom reads are prevented
Ans: c

15. What statements are correct about positioned updates (i.e. cursor updates) in ResultSets?
a. Using the cursor technique is currently the only possible way to change the data in the current row of a ResultSet
b. Insert statements are only supported when using scrollable cursors.
c. Only scrollable updateable ResultSets can use this approach to change the data in the current row of a ResultSet
d. The name of the cursor is specified by the setCursorName(String name) method the Statement object.
Ans: b,d

16. How can you execute a stored procedure in the database?
a. Call method execute() on a CallableStatement object
b. Call method executeProcedure() on a Statement object
c. Call method execute() on a StoredProcedure object
d. Call method run() on a ProcedureCommand object
Ans: a

17. What happens if you call the method close() on a ResultSet object?
a. the method close() does not exist for a ResultSet. Only Connections can be closed.
b. the database and JDBC resources are released
c. you will get a SQLException, because only Statement objects can close ResultSets
d. the ResultSet, together with the Statement which created it and the Connection from which the Statement was retrieved, will be closed and release all database and JDBC resources
Ans: b

18. What happens if you call deleteRow() on a ResultSet object?
a. The row you are positioned on is deleted from the ResultSet, but not from the database.
b. The row you are positioned on is deleted from the ResultSet and from the database
c. The result depends on whether the property synchronizeWithDataSource is set to true or false
d. You will get a compile error: the method does not exist because you can not delete rows from a ResultSet
Ans: b

19. What statements are correct about batched insert and updates? (2 answers)
a. To create a batch of insert and update statements, you create an object of type Batch, and call the method addStatement(String statement) for each statement you want to execute in the batch
b. Batch insert and updates are only possible when making use of parameterized queries.
c. To do a batched update/insert, you call addBatch(String statement) on a Statement object for each statement you want to execute in the batch
d. To execute a batched update/insert, you call the executeBatch() method on a Statement object
Ans: c,d

20. What is correct about DDL statements (create, grant,…)?
a. DDL statements are treated as normal SQL statements, and are executed by calling the execute() method on a Statement (or a sub interface thereof) object
b. To execute DDL statements, you have to install additional support files
c. DDL statements can not be executed by making use of JDBC, you should use the native database tools for this.
d. Support for DDL statements will be a feature of a future release of JDBC
Ans: a

21. The JDBC-ODBC Bridge supports multiple concurrent open statements per connection?
a. True
b. False
Ans: a

22. Which of the following allows non repeatable read in JDBC Connection?
a. TRANSACTION_READ_UNCOMMITTED
b. TRANSACTION_READ_COMMITTED
c. TRANSACTION_SERIALIZABLE
d. TRANSACTION_REPEATABLE_READ
Ans: d

23. Which of the following statements is false as far as different type of statements is concern in JDBC?
a. Regular Statement
b. Prepared Statement
c. Callable Statement
d. Interim Statement
Ans: d

24. Which of the following methods are needed for loading a database driver in JDBC?
a. registerDriver() method
b. Class.forName()
c. Both A and B
d. getConnection()
Ans: c

25. Which of the following is false as far as type 4 driver is concern?
a. Type 4 driver is “native protocol, pure java” driver
b. Type 4 drivers are 100% Java compatible
c. Type 4 drivers uses Socket class to connect to the database
d. Type 4 drivers can not be used with Netscape
Ans: d

26. To execute a stored procedure “totalStock” in a database server, which of the following code snippet is used?
a. Statement stmt = connection.createStatement();stmt.execute(“totalStock()”);
b. CallableStatement clbstmnt = con.prepareCall(“{call totalStock}”);cs.executeQuery();
c. StoreProcedureStatement stmt=connection.createStoreProcedure(“totalStock()”);spstmt.executeQuery();
d. PrepareStatement pstmt = connection.prepareStatement(“totalStock()”);pstmt.execute();
Ans: b

27. Which driver is efficient and always preferable for using JDBC applications?
a. Type – 4
b. Type – 1
c. Type – 3
d. Type – 2
Ans: a

28. JDBC facilitates to store the java objects by using which of the methods of PreparedStatement
setObject () 2. setBlob() 3. setClob()
a. 1, 2
b. 1,2,3
c. 1,3
d. 2,3
Ans: b

29. Which statement is static and synchronized in JDBC API?
a. executeQuery()
b. executeUpdate()
c. getConnection()
d. prepareCall()
Ans: c

30. The JDBC-ODBC bridge is
a. Three tiered
b. Multithreaded
c. Best for any platform
d. All of the above
Ans: b

31. All raw data types (including binary documents or images) should be read and uploaded to the database as an array of
a. byte
b. int
c. boolean
d. char
Ans: a

32. The class java.sql.Timestamp has its super class as
a. java.sql.Time
b. java.util.Date
c. java.util.Time
d. None of the above
Ans: b

33. BLOB, CLOB, ARRAY and REF type columns can be updated in
a. JDBC 1.0
b. JDBC 4.0
c. JDBC 2.0
d. JDBC 3.0
Ans: d

34. Which of the following methods finds the maximum number of connections that a specific driver can obtain?
a. Database.getMaxConnections
b. Connection.getMaxConnections
c. DatabaseMetaData.getMaxConnections
d. ResultSetMetaData.getMaxConnections
Ans: c

35. Are prepared statements actually compiled?
a. Yes, they compiled
b. No, they are bound by the JDBC driver
Ans: a

36. When the message “No Suitable Driver” occurs?
a. When the driver is not registered by Class.forname() method
b. When the user name, password and the database does not match
c. When the JDBC database URL passed is not constructed properly
d. When the type 4 driver is used
Ans: c

37. Which driver is called as thin-driver in JDBC?
a. Type-4 driver
b. Type-1 driver
c. Type-3 driver
d. Type-2 driver
Ans: a

38. How many transaction isolation levels are defined in java.sql.Connection interface?
a. 4
b. 3
c. 5
d. 2
Ans: c

39. Which method is used to perform DML statements in JDBC?
a. execute()
b. executeQuery()
c. executeUpdate()
d. executeResult()
Ans: c

40. What is the disadvantage of Type-4 Native-Protocol Driver?
a. At client side, a separate driver is needed for each database.
b. Type-4 driver is entirely written in Java
c. The driver converts JDBC calls into vendor-specific database protocol
d. It does not support to read MySQL data.
Ans: a

41. Which isolation level prevents dirty read in JDBC, connection class.
A. TRANSACTION_READ_ COMMITTED
B. TRANSACTION_UNREAD_ COMMITTED
Ans: A

42. State true or false . Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection ?
A. TRUE
B. FALSE
Ans: A

43. Which of the following describes the correct sequence of the steps involved in making a connection with a database.
1. Loading the driver
2. Process the results.
3. Making the connection with the database.
4. Executing the SQL statements.
A. 1,3,4,2
B. 1,2,3,4
C. 2,1,3,4
D. 4,1,2,3
Ans: A

44. Two parts of JDBC 2.0 API are
The JDBC 2.0 core API (the java.sql package), which is included in the JavaTM 2 SDK, Standard Edition 5. The JDBC 2.0 Optional Package API (the javax.sql package), which is available separately or as part of the Java 2 SDK, Enterprise Edition
A. TRUE
B. FALSE
Ans: A

45. Which of the following values can be replaced in the place of 1 and 2 below Statement
stmt = con.createStatement(1, 2);
A. ResultSet. TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY ResultSet. TYPE_SCROLL_INSENSITIVE , ResultSet. CONCUR_UPDATABLE
B. ResultSet. TYPE_SCROLL_INSENSITIVE , ResultSet. CONCUR_UPDATABLE, ResultSet. TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY
Ans: A

46. State true or false. Is the JDBC-ODBC bridge multithreaded ?
A. TRUE
B. FALSE
Ans: A

47. State true or false Can we retrieve a whole row of data at once, instead of calling an individual ResultSet.getXXX method for each column ?
A. TRUE
B. FALSE
Ans: A

48. State true or false . Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?
A. TRUE
B. FALSE
Ans: A

49. ________ is an open source DBMS product that runs on UNIX, Linux and Windows.
A. MySQL
B. JSP/SQL
C. JDBC/SQL
D. Sun ACCESS
Ans: A

50. What servlet processor was developed by Apache Foundation and Sun?
A. Apache Tomcat
B. Sun servlet processor
C. Apache Web server
D. None of the above is correct.
Ans: A

Leave a Reply

Your email address will not be published. Required fields are marked *