This set of Advanced Java Multiple Choice Questions & Answers (MCQs) on “JDBC”.
1. Which of the following contains both date and time? Answer: d 2. Which of the following is advantage of using JDBC connection pool? Answer: d 3. Which of the following is advantage of using PreparedStatement in Java? Answer: c 4. Which one of the following contains date information? Answer: a 5. What does setAutoCommit(false) do? Answer: c 6. Which of the following is used to call stored procedure? Answer: c 7. Which of the following is used to limit the number of rows returned? Answer: a 8. Which of the following is method of JDBC batch process? Answer: d 9. Which of the following is used to rollback a JDBC transaction? Answer: a 10. Which of the following is not a JDBC connection isolation levels? Answer: d
a) java.io.date
b) java.sql.date
c) java.util.date
d) java.util.dateTime
Clarification: java.util.date contains both date and time. Whereas, java.sql.date contains only date.
a) Slow performance
b) Using more memory
c) Using less memory
d) Better performance
Clarification: Since the JDBC connection takes time to establish. Creating connection at the application start-up and reusing at the time of requirement, helps performance of the application.
a) Slow performance
b) Encourages SQL injection
c) Prevents SQL injection
d) More memory usage
Clarification: PreparedStatement in Java improves performance and also prevents from SQL injection.
a) java.sql.TimeStamp
b) java.sql.Time
c) java.io.Time
d) java.io.TimeStamp
Clarification: java.sql.Time contains only time. Whereas, java.sql.TimeStamp contains both time and date.
a) commits transaction after each query
b) explicitly commits transaction
c) does not commit transaction automatically after each query
d) never commits transaction
Clarification: setAutoCommit(false) does not commit transaction automatically after each query. That saves a lot of time of the execution and hence improves performance.
a) Statement
b) PreparedStatement
c) CallableStatment
d) CalledStatement
Clarification: CallableStatement is used in JDBC to call stored procedure from Java program.
a) setMaxRows(int i)
b) setMinRows(int i)
c) getMaxrows(int i)
d) getMinRows(int i)
Clarification: setMaxRows(int i) method is used to limit the number of rows that the database returns from the query.
a) setBatch()
b) deleteBatch()
c) removeBatch()
d) addBatch()
Clarification: addBatch() is a method of JDBC batch process. It is faster in processing than executing one statement at a time.
a) rollback()
b) rollforward()
c) deleteTransaction()
d) RemoveTransaction()
Clarification: rollback() method is used to rollback the transaction. It will rollback all the changes made by the transaction.
a) TRANSACTION_NONE
b) TRANSACTION_READ_COMMITTED
c) TRANSACTION_REPEATABLE_READ
d) TRANSACTION_NONREPEATABLE_READ
Clarification: TRANSACTION_NONREPEATABLE_READ is not a JDBC connection isolation level.