Home Subjects Java Programming JDBC

Java Programming
JDBC

Java OOP, collections, multithreading

46 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 46
Topics in Java Programming
Q.31 Medium JDBC
Which JDBC method allows you to retrieve column information such as column name, type, and size?
A ResultSetMetaData
B DatabaseMetaData
C ColumnMetaData
D TableMetaData
Correct Answer:  A. ResultSetMetaData
EXPLANATION

ResultSetMetaData interface provides information about the columns returned in a ResultSet, such as getColumnName(), getColumnType(), getColumnCount(), etc. Obtained via rs.getMetaData().

Test
Q.32 Medium JDBC
In JDBC, which concurrency type allows modifications to the ResultSet?
A CONCUR_READ_ONLY
B CONCUR_UPDATABLE
C CONCUR_WRITE
D CONCUR_MODIFIABLE
Correct Answer:  B. CONCUR_UPDATABLE
EXPLANATION

CONCUR_UPDATABLE is the ResultSet concurrency type that allows the ResultSet to be updated. CONCUR_READ_ONLY prevents modifications.

Test
Q.33 Medium JDBC
Which JDBC feature allows multiple SQL statements to be sent to the database in a single round trip?
A Bulk operations
B Batch processing
C Transaction management
D Connection pooling
Correct Answer:  B. Batch processing
EXPLANATION

Batch processing allows multiple SQL statements to be grouped and sent together using addBatch() and executeBatch() methods, improving performance by reducing network overhead.

Test
Q.34 Medium JDBC
In JDBC, what does the ResultSet.absolute(5) method do?
A Moves cursor 5 positions forward
B Moves cursor to the 5th row
C Checks if row 5 exists
D Returns the absolute value at row 5
Correct Answer:  B. Moves cursor to the 5th row
EXPLANATION

The absolute(int row) method moves the cursor to the specified row number (1-based indexing). absolute(5) moves the cursor directly to row 5.

Test
Q.35 Medium JDBC
Which method is used to retrieve metadata about the database in JDBC?
A getMetaData()
B getDatabaseMetaData()
C getDBMetaData()
D fetchMetaData()
Correct Answer:  B. getDatabaseMetaData()
EXPLANATION

The getDatabaseMetaData() method is called on a Connection object to retrieve DatabaseMetaData information about the database, such as table names, column information, etc.

Test
Q.36 Medium JDBC
What is the correct way to use try-with-resources for JDBC operations?
A try(Connection con = DriverManager.getConnection(url)) { }
B try { Connection con = DriverManager.getConnection(url); }
C try-with-resources { Connection con = DriverManager.getConnection(url); }
D resource(Connection con = DriverManager.getConnection(url)) { }
Correct Answer:  A. try(Connection con = DriverManager.getConnection(url)) { }
EXPLANATION

The try-with-resources statement automatically closes resources implementing AutoCloseable. Since Connection implements AutoCloseable, it will be automatically closed.

Test
Q.37 Medium JDBC
Which exception is thrown when a database operation violates a unique constraint in JDBC?
A SQLException
B DataAccessException
C ConstraintViolationException
D SQLIntegrityConstraintViolationException
Correct Answer:  D. SQLIntegrityConstraintViolationException
EXPLANATION

SQLIntegrityConstraintViolationException is a specific subclass of SQLException that is thrown when integrity constraint violations occur, such as unique constraint violations.

Test
Q.38 Medium JDBC
What does the PreparedStatement interface provide that Statement does not?
A Better error handling
B SQL injection prevention through parameterized queries
C Faster execution due to precompilation
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

PreparedStatement provides both parameterized queries (preventing SQL injection) and precompilation of SQL statements, resulting in better security and performance compared to Statement.

Test
Q.39 Medium JDBC
Which of the following is the correct way to close JDBC resources to prevent resource leaks?
A Close ResultSet, Statement, then Connection
B Close Connection only
C Use try-with-resources statement
D Both A and C are correct
Correct Answer:  D. Both A and C are correct
EXPLANATION

Resources should be closed in reverse order of creation (ResultSet → Statement → Connection), or preferably using try-with-resources which auto-closes resources.

Test
Q.40 Medium JDBC
What does the setAutoCommit(false) method do in JDBC?
A Disables automatic transaction commit
B Enables automatic transaction commit
C Rolls back current transaction
D Closes the connection
Correct Answer:  A. Disables automatic transaction commit
EXPLANATION

setAutoCommit(false) disables automatic commit, allowing multiple statements to be part of single transaction. Manual commit() or rollback() must be called.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips