Java Programming — JDBC
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 71–80 of 100 questions in JDBC
Q.71 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.

Take Test
Q.72 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.

Take Test
Q.73 Hard JDBC
What is the difference between update() and updateRow() methods in ResultSet?
A update() modifies a single column, updateRow() commits all column changes
B update() is for SELECT queries, updateRow() is for UPDATE queries
C update() is for integers, updateRow() is for all data types
D There is no difference; they are synonymous
Correct Answer:  A. update() modifies a single column, updateRow() commits all column changes
EXPLANATION

update*() methods (like updateInt(), updateString()) modify individual column values in the current row, while updateRow() commits all these changes to the database.

Take Test
Q.74 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.

Take Test
Q.75 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.

Take Test
Q.76 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.

Take Test
Q.77 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.

Take Test
Q.78 Easy JDBC
In JDBC, what is the purpose of the Class.forName() method?
A To load and register the JDBC driver
B To establish a database connection
C To execute a SQL query
D To fetch data from ResultSet
Correct Answer:  A. To load and register the JDBC driver
EXPLANATION

Class.forName() is used to load the JDBC driver class dynamically and register it with the DriverManager. For example: Class.forName("com.mysql.cj.jdbc.Driver");

Take Test
Q.79 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.

Take Test
Q.80 Easy JDBC
Which interface represents a single row of data retrieved from a database in JDBC?
A Statement
B ResultSet
C Connection
D DatabaseMetaData
Correct Answer:  B. ResultSet
EXPLANATION

ResultSet interface represents the result set of a query. It contains the data returned from a database query and provides methods to access and traverse through the rows.

Take Test
IGET
iget AI
Online · Ask anything about exams
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