JDBC online quiz (Multiple Choice Questions and Answers)

In this post, I will be sharing JDBC online quiz - multiple choice questions with answers. JDBC stands for Java database connectivity. Below we are sharing 14 questions with answers.

Read Also: JDBC Interview Questions and Answers

JDBC Online Quiz - Multiple Choice Questions and Answers (MCQ)

1. JDBC classes belong to which packages

a. javax.jdbc and jdbc

b. javax.rdb and rdb

c. javax.sql and sql

d. java.jdbc.sql and JDBC

The correct answer is C.



2. Correct order of sequences to create database connection?

a. Import packages related to JDBC.

b. Database connection to be opened.

c. Register & load the JDBC driver.

d. A query resultset to be returned by executing the statement object.

e. Statement object is created for performing a query.

f. Close the statement & resultset objects.

g. Processing of the resultset.

h. Close the connection.

i. b, a, c, d, h, e, g, f
ii. a, c, b, e, d, g, f, h
iii. a, b, c, e, g, d, h, f
iv. a, c, b, d, e, f, g, h

The correct answer is ii.



3. Connection interface provides how many isolation levels in JDBC

a. 3

b. 4

c. 1

d. 2


The correct answer is B.



4. synchronized & static method in JDBC API is:

a. getConnection()

b. prepareCall()

c. executeUpdate()

d. executeQuery()


The correct answer is A.



5. Execution of Parameterized queries can be done by?

a. ParameterizedStatement

b. PreparedStatement

c. Parameterized & CallableStatement Statement

d. All


The correct answer is B.



6. Dirty read is prevented by which isolation level

a. TRANSACTION_READ_UNCOMMITTED

b. TRANSACTION_READ_COMMITTED

c. TRANSACTION_READABLE_READ

d. TRANSACTION_NONE

The correct answer is B.



7. setAutoCommit(false) does what :

a. Never commit the transactions.

b. Transaction is explicitly committed.

c. Transactions will not be committed automatically after each query.

d. Transactions will be clubbed together based on clubbing size and will be committed automatically.

The correct answer is B.



8. Order in which database resources should be closed :

a. ResultSet, Connection, and then Statements

b. Connection, Statements, and then ResultSet

c. ResultSet, Statements, and then Connection

d. Statements, ResultSet, and then Connection

The correct answer is C.



9. Data type used to store files in the database table :

a. BLOB

b. CLOB

c. File

d. Both a and b

The correct answer is B.



10. Which of the following statements are true?

a. Statement encapsulates an SQL statement that is sent to the database for parsing and compilation

b. Statement encapsulates an SQL statement that is sent to the database for planning and execution.

c. Different requests can be mapped to the same prepared statement with different arguments to execute the same execution plan using a PreparedStatement.

d. Prepared statements use bind variables making them less secure as they are vulnerable to SQL injection attacks.

The correct answers are A, B, and C.



11. Which of the following statements are true?

a. Before sending to the database, the JDBC driver performs the conversion between the Java data type to the appropriate JDBC type.

b. Application server like WebLogic, WebSphere, JBoss, and Tomcat provides the facilities to configure connection pooling.

c. JDBC uses a custom mapping for most data types.

d. Components like Apache Commons DBCP Component can be used to configure connection pooling.

The correct answers are A, B, and D.



12. Which of the following statements are true?

a. If the ResultSet needs more rows, setFetchSize(int) determines how many rows will be read from the database.

b. ResultSet data returned by the database is affected by setFetchSize(int).

c. There is always a chance that the first transaction might rollback the change which causes the second transaction reads an invalid value.

d. In typical database transactions, suppose one transaction reads & changes the value while the second transaction reads the value before committing or rolling back by the first transaction, this is called a 'dirty read'.

The correct answers are A, B, C, and D.



13. Which of the following statements are correct for Connection Pooling

a. It provides better performance

b. Creating connection at the application start-up and reusing at the time of requirement, decreases the performance of the application

c. Connection pooling configurations are facilitated by Application servers like WebSphere, Tomcat, WebLogic & JBoss.

d. Components like Apache Commons DBCP Component can be used to configure connection pooling.

The correct answers are A, C, and D.



14. Which of the following statements are true?

a. JDBC is an API for bridging the object-relational mismatch between relational databases & OO programs

b. JDBC refers to Java DataBase Connectivity

c. A DataSource represents a factory of connections to a physical data source

d. JDBC acts as an API to access relational databases


The correct answers are B and C.


That's all for today. Please mention in the comments if you have faced any other JDBC(Java Database Connectivity) Quiz MCQ question that needs to be added to the above list.

About The Author

Subham Mittal has worked in Oracle for 3 years.
Enjoyed this post? Never miss out on future posts by subscribing JavaHungry