Advanced Java MCQ – JDBC

This set of Advanced Java Multiple Choice Questions & Answers (MCQs) focuses on “JDBC”.

1. Which of the following contains both date and time?
a) java.io.date
b) java.sql.date
c) java.util.date
d) java.util.dateTime
View Answer

Answer: d
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
View Answer

Answer: d
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
View Answer

Answer: c
Explanation: PreparedStatement in Java improves performance and also prevents from SQL injection.
advertisement
advertisement

4. Which one of the following contains date information?
a) java.sql.TimeStamp
b) java.sql.Time
c) java.io.Time
d) java.io.TimeStamp
View Answer

Answer: a
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
View Answer

Answer: c
Explanation: setAutoCommit(false) does not commit transaction automatically after each query. That saves a lot of time of the execution and hence improves performance.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Which of the following is used to call stored procedure?
a) Statement
b) PreparedStatement
c) CallableStatment
d) CalledStatement
View Answer

Answer: c
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)
View Answer

Answer: a
Explanation: setMaxRows(int i) method is used to limit the number of rows that the database returns from the query.
advertisement

8. Which of the following is method of JDBC batch process?
a) setBatch()
b) deleteBatch()
c) removeBatch()
d) addBatch()
View Answer

Answer: d
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?
a) rollback()
b) rollforward()
c) deleteTransaction()
d) RemoveTransaction()
View Answer

Answer: a
Explanation: rollback() method is used to rollback the transaction. It will rollback all the changes made by the transaction.
advertisement

10. Which of the following is not a JDBC connection isolation levels?
a) TRANSACTION_NONE
b) TRANSACTION_READ_COMMITTED
c) TRANSACTION_REPEATABLE_READ
d) TRANSACTION_NONREPEATABLE_READ
View Answer

Answer: d
Explanation: TRANSACTION_NONREPEATABLE_READ is not a JDBC connection isolation level.

Sanfoundry Global Education & Learning Series – Java Programming Language.

To practice all areas of Java language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.