Java Programming — JDBC
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 11–20 of 100 questions in JDBC
Q.11 Medium JDBC
In JDBC 2024-25, which data type mapping is incorrect for Java to SQL?
A int → INTEGER
B String → VARCHAR
C boolean → BOOLEAN
D byte[] → CHAR
Correct Answer:  D. byte[] → CHAR
EXPLANATION

byte[] should map to BLOB (Binary Large Object), not CHAR. CHAR is for single character types.

Take Test
Q.12 Easy JDBC
What is the difference between commit() and rollback() in JDBC transactions?
A commit() saves changes, rollback() undoes them
B Both perform the same function
C rollback() is faster than commit()
D commit() is used for SELECT queries, rollback() for UPDATE
Correct Answer:  A. commit() saves changes, rollback() undoes them
EXPLANATION

commit() permanently saves all changes made during the transaction, while rollback() discards all changes and reverts to the previous state.

Take Test
Q.13 Hard JDBC
A developer wants to retrieve data from a stored procedure that returns multiple result sets and output parameters. Which approach is correct?
A Use Statement with executeQuery()
B Use PreparedStatement with execute()
C Use CallableStatement with registerOutParameter() and execute()
D Use PreparedStatement with setFetchSize()
Correct Answer:  C. Use CallableStatement with registerOutParameter() and execute()
EXPLANATION

CallableStatement is specifically designed for stored procedures, supporting registerOutParameter() for output parameters and getMoreResults() for multiple result sets.

Take Test
Q.14 Medium JDBC
Which method in ResultSet is used to check if a column value is NULL?
A isNull()
B wasNull()
C checkNull()
D getNullValue()
Correct Answer:  B. wasNull()
EXPLANATION

wasNull() returns true if the last retrieved value was NULL in the database, checked after calling a getter method like getString() or getInt().

Take Test
Q.15 Medium JDBC
In a multi-threaded JDBC application, what should be the approach for Connection object usage?
A Share single Connection object across all threads
B Each thread should use its own Connection from the pool
C Create new Connection for each database operation
D Use static Connection objects
Correct Answer:  B. Each thread should use its own Connection from the pool
EXPLANATION

Connection objects are not thread-safe. Each thread should obtain its own Connection from a thread-safe connection pool to avoid race conditions.

Take Test
Advertisement
Q.16 Medium JDBC
What does the setMaxRows() method in Statement do?
A Limits the number of rows returned by a query
B Sets the maximum number of connections
C Defines batch size for updates
D Controls transaction timeout
Correct Answer:  A. Limits the number of rows returned by a query
EXPLANATION

setMaxRows() limits the number of rows returned by executeQuery(), useful for memory management when dealing with large result sets.

Take Test
Q.17 Easy JDBC
Which exception is thrown when a JDBC driver is not found in the classpath?
A SQLException
B ClassNotFoundException
C DriverNotFoundException
D JDBCException
Correct Answer:  B. ClassNotFoundException
EXPLANATION

When Class.forName() cannot locate the driver class, it throws ClassNotFoundException, indicating the driver JAR is not in the classpath.

Take Test
Q.18 Medium JDBC
Consider a scenario where a developer uses getConnection() without closing it. What is the potential impact?
A Database performance remains unaffected
B Connection leak occurs, exhausting available database connections
C Automatic rollback happens
D Query execution becomes slower temporarily
Correct Answer:  B. Connection leak occurs, exhausting available database connections
EXPLANATION

Unclosed connections remain allocated and unavailable for other operations, eventually exhausting the connection pool and causing connection exhaustion errors.

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

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

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