Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 271–280 of 958
Topics in Java Programming
Q.271 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.272 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.273 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
Q.274 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.275 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.276 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.277 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.278 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
Q.279 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.

Take Test
Q.280 Easy JDBC
In JDBC, what does the BatchUpdate feature allow developers to do?
A Execute single queries faster
B Execute multiple queries in a single batch for improved performance
C Create backup of database
D Monitor database connections
Correct Answer:  B. Execute multiple queries in a single batch for improved performance
EXPLANATION

addBatch() and executeBatch() methods allow multiple SQL statements to be grouped and executed together, reducing network traffic and improving performance.

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