Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 161–170 of 476
Topics in Java Programming
Q.161 Medium JDBC
Which JDBC method is used to retrieve metadata information about the database?
A getMetaData()
B getDatabaseInfo()
C getConnection().getInfo()
D getProperties()
Correct Answer:  A. getMetaData()
EXPLANATION

Connection.getMetaData() returns a DatabaseMetaData object containing information about the database and driver.

Take Test
Q.162 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().

Take Test
Q.163 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.164 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.165 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.166 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.167 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.168 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.169 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.170 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.

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