This set of Advanced Java Multiple Choice Questions & Answers (MCQs) focuses on “JDBC”.
1. Which of the following contains both date and time?
Explanation: java.util.date contains both date and time. Whereas, java.sql.date contains only date.
2. Which of the following is advantage of using JDBC connection pool?
a) Slow performance
b) Using more memory
c) Using less memory
d) Better performance
Explanation: 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.
3. Which of the following is advantage of using PreparedStatement in Java?
a) Slow performance
b) Encourages SQL injection
c) Prevents SQL injection
d) More memory usage
Explanation: PreparedStatement in Java improves performance and also prevents from SQL injection.
4. Which one of the following contains date information?
Explanation: java.sql.Time contains only time. Whereas, java.sql.TimeStamp contains both time and date.
5. What does setAutoCommit(false) do?
a) commits transaction after each query
b) explicitly commits transaction
c) does not commit transaction automatically after each query
d) never commits transaction
Explanation: setAutoCommit(false) does not commit transaction automatically after each query. That saves lot of time of the execution and hence improves performance.
6. Which of the following is used to call stored procedure?
Explanation: CallableStatement is used in JDBC to call stored procedure from Java program.
7. Which of the following is used to limit the number of rows returned?
a) setMaxRows(int i)
b) setMinRows(int i)
c) getMaxrows(int i)
d) getMinRows(int i)
Explanation: setMaxRows(int i) method is used to limit the number of rows that the database returns from the query.
8. Which of the following is method of JDBC batch process?
Explanation: addBatch() is a method of JDBC batch process. It is faster in processing than executing one statement at a time.
9. Which of the following is used to rollback a JDBC transaction?
Explanation: rollback() method is used to rollback the transaction. It will rollback all the changes made by the transaction.
10. Which of the following is not a JDBC connection isolation levels?
Explanation: TRANSACTION_NONREPEATABLE_READ is not a JDBC connection isolation level.
Sanfoundry Global Education & Learning Series – Java Programming Language.
To practice all features of Java programming language, here is complete set on 1000+ Multiple Choice Questions and Answers on Java.