Thursday, March 3, 2016

MCQ Advanced Java Questions & Answers – 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.

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.

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.

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.

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.


No comments:

Post a Comment

CORBA Java Tutorial using Netbeans and Java 8.

CORBA-Example A simple CORBA implementation using Java Echo.idl module EchoApp{ interface Echo{ string echoString(); }; }; ...