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 11–20 of 46
Topics in Java Programming
Q.11 Medium JDBC
What is the purpose of Connection pooling in JDBC applications?
A To store query results temporarily
B To reuse database connections instead of creating new ones each time
C To encrypt database connections
D To monitor database performance
Correct Answer:  B. To reuse database connections instead of creating new ones each time
EXPLANATION

Connection pooling maintains a pool of reusable connections, reducing the overhead of creating new connections for each request, improving application performance.

Test
Q.12 Medium JDBC
A developer needs to execute a query that returns multiple result sets. Which Statement type should be used?
A Statement with executeQuery()
B PreparedStatement with setFetchSize()
C Statement with execute() or PreparedStatement with execute()
D CallableStatement only
Correct Answer:  C. Statement with execute() or PreparedStatement with execute()
EXPLANATION

The execute() method returns a boolean and can handle multiple result sets via getResultSet(), getUpdateCount(), and getMoreResults() methods.

Test
Q.13 Medium JDBC
Which JDBC driver type is considered the most portable across different databases?
A Type 1 - JDBC-ODBC Bridge
B Type 2 - Native API Driver
C Type 3 - Network Protocol Driver
D Type 4 - Thin Driver
Correct Answer:  D. Type 4 - Thin Driver
EXPLANATION

Type 4 drivers are pure Java implementations that directly communicate with the database, making them platform-independent and most portable.

Test
Q.14 Medium JDBC
What happens if you call next() on a ResultSet after the last row?
A Throws SQLException
B Returns false
C Returns true
D Throws NoSuchElementException
Correct Answer:  B. Returns false
EXPLANATION

next() returns false when the cursor is positioned beyond the last row, indicating no more rows available.

Test
Q.15 Medium JDBC
Which statement should be used when you need to retrieve column information without executing multiple queries?
A Statement with multiple executeQuery()
B PreparedStatement
C ResultSetMetaData
D DatabaseMetaData
Correct Answer:  C. ResultSetMetaData
EXPLANATION

ResultSetMetaData provides column information directly from the ResultSet without additional queries.

Test
Q.16 Medium JDBC
What is the difference between execute() and executeUpdate() methods?
A execute() returns boolean, executeUpdate() returns int
B execute() can execute any SQL statement, executeUpdate() only for DML
C Both A and B are correct
D There is no difference
Correct Answer:  C. Both A and B are correct
EXPLANATION

execute() returns true/false and handles any SQL, while executeUpdate() returns affected rows count for DML statements only.

Test
Q.17 Medium JDBC
In JDBC, which class is used to retrieve database metadata information?
A ResultSet
B Statement
C DatabaseMetaData
D Connection
Correct Answer:  C. DatabaseMetaData
EXPLANATION

DatabaseMetaData provides information about the database, tables, columns, and other database properties.

Test
Q.18 Medium JDBC
What does ResultSetMetaData.getColumnCount() return?
A Number of rows in ResultSet
B Number of columns in ResultSet
C Column data type
D Column name
Correct Answer:  B. Number of columns in ResultSet
EXPLANATION

getColumnCount() returns the total number of columns present in the ResultSet.

Test
Q.19 Medium JDBC
What is the benefit of using PreparedStatement over Statement for repeated queries?
A Faster execution due to pre-compilation
B Automatic SQL injection prevention
C Better readability of code
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

PreparedStatement offers both pre-compilation for performance and SQL injection prevention through parameterized queries.

Test
Q.20 Medium JDBC
Which JDBC method executes UPDATE, INSERT, or DELETE statements?
A executeQuery()
B execute()
C executeUpdate()
D executeBatch()
Correct Answer:  C. executeUpdate()
EXPLANATION

executeUpdate() executes DML statements and returns the number of rows affected.

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