Top MCQs on JDBC (Advanced Java)

21.) Why is it important to close JDBC resources such as connections, statements, and result sets?

A) To release database locks
B) To improve query performance
C) To avoid resource leaks and free up resources
D) To prevent SQL injection attacks

Answer: Option C

Explanation: It is important to close JDBC resources to avoid resource leaks and free up system resources.

22.) In which order should you close JDBC resources to ensure proper resource management?

A) Statement, Connection, ResultSet
B) ResultSet, Statement, Connection
C) Connection, Statement, ResultSet
D) ResultSet, Connection, Statement

Answer: Option B

Explanation: You should generally close the ResultSet first, followed by the Statement, and then the Connection for proper resource management.

23.) What is a database transaction in the context of JDBC?

A) A query that retrieves data from multiple tables
B) A single SQL statement
C) A group of SQL statements executed as a single unit
D) A stored procedure in the database

Answer: Option C

Explanation: In the context of JDBC, a database transaction is a group of SQL statements executed as a single unit, either all succeeding or all failing.

24.) What is the purpose of a JDBC Connection’s commit() method?

A) To start a new transaction
B) To roll back a transaction
C) To save changes made within a transaction
D) To execute a SQL query

Answer: Option C

Explanation: The commit() method of a JDBC Connection is used to save changes made within a transaction to the database.

25.) How can you roll back a transaction in JDBC?

A) By using the rollback() method of the Connection object
B) By using the executeRollback() method of the Statement object
C) By executing an SQL query with the ROLLBACK statement
D) By closing the JDBC connection

Answer: Option A

Explanation: You can roll back a transaction in JDBC by using the rollback() method of the Connection object.

26.) What is connection pooling in JDBC?

A) A mechanism for storing database connection strings
B) A technique for optimizing SQL queries
C) A method for managing and reusing database connections
D) A way to secure database credentials

Answer: Option C

Explanation: Connection pooling in JDBC is a technique for managing and reusing database connections to improve efficiency.

27.) Which JDBC feature allows you to execute multiple SQL statements in a batch?

A) Batch processing
B) Prepared statements
C) Transaction management
D) Connection pooling

Answer: Option A

Explanation: Batch processing in JDBC allows you to execute multiple SQL statements in a batch, reducing the overhead of individual statement execution.

28.) What is a stored procedure in the context of databases and JDBC?

A) A query that retrieves data from multiple tables
B) A predefined set of SQL statements that can be executed in one call
C) A query with dynamic parameters
D) An optimized SQL query

Answer: Option B

Explanation: In the context of databases and JDBC, a stored procedure is a predefined set of SQL statements that can be executed in one call.

29.) Which JDBC interface is used to call stored procedures in the database?

A) Statement
B) PreparedStatement
C) CallableStatement
D) ResultSet

Answer: Option C

Explanation: The CallableStatement interface is used to call stored procedures in the database using JDBC.

30.) What is a connection pool, and why is it used in JDBC?

A) A pool of JDBC drivers for redundancy
B) A pool of SQL queries for performance optimization
C) A pool of preconfigured database connections for reusability and efficiency
D) A pool of database tables for data storage

Answer: Option C

Explanation: A connection pool is a pool of preconfigured database connections used in JDBC to enhance reusability and efficiency when connecting to databases.

Leave a Reply

Your email address will not be published. Required fields are marked *