Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 261–270 of 958
Topics in Java Programming
Q.261 Medium JDBC
In JDBC 2024-25, which exception is thrown when attempting to use a closed Connection object?
A SQLException
B SQLClientInfoException
C SQLInvalidAuthorizationSpecException
D SQLNonTransientConnectionException
Correct Answer:  A. SQLException
EXPLANATION

A SQLException (specifically a SQLNonTransientConnectionException as a subclass) is thrown when operations are attempted on a closed Connection. SQLException is the general exception for database access errors.

Take Test
Q.262 Medium JDBC
When using ResultSet in JDBC, which cursor type allows bidirectional movement through rows but does not reflect database changes?
A TYPE_FORWARD_ONLY
B TYPE_SCROLL_INSENSITIVE
C TYPE_SCROLL_SENSITIVE
D TYPE_DYNAMIC
Correct Answer:  B. TYPE_SCROLL_INSENSITIVE
EXPLANATION

TYPE_SCROLL_INSENSITIVE allows movement in both directions (previous, next, absolute) but doesn't reflect changes made to the database after the ResultSet was created. TYPE_SCROLL_SENSITIVE would reflect changes.

Take Test
Q.263 Medium JDBC
A developer needs to execute the same SQL query multiple times with different parameters. Which JDBC feature should be used to optimize performance?
A Statement with loop execution
B PreparedStatement with parameterized queries
C CallableStatement for all queries
D Multiple Connection objects
Correct Answer:  B. PreparedStatement with parameterized queries
EXPLANATION

PreparedStatement pre-compiles the query and allows parameter binding, reducing overhead and improving performance for repeated executions. It also prevents SQL injection.

Take Test
Q.264 Easy JDBC
In a JDBC application, which interface is responsible for executing SQL queries and returning ResultSet objects?
A Statement
B Connection
C Driver
D DataSource
Correct Answer:  A. Statement
EXPLANATION

The Statement interface is used to execute SQL queries. Connection creates the statement, Driver manages connections, and DataSource provides connection pooling, but Statement is the actual executor.

Take Test
Q.265 Hard JDBC
In a JDBC application using batch updates, what happens if one statement in the batch fails?
A All statements are executed, and failure is reported
B All statements are rolled back automatically
C Only failed statement is skipped
D Behavior depends on database configuration
Correct Answer:  D. Behavior depends on database configuration
EXPLANATION

executeBatch() behavior on failure varies by database and driver. BatchUpdateException is thrown, containing update counts for each statement. Explicit transaction control is recommended.

Take Test
Q.266 Medium JDBC
Which JDBC feature allows monitoring of database metadata like table structure and column information?
A DatabaseMetaData interface
B ResultSetMetaData interface
C ParameterMetaData interface
D StatementMetaData interface
Correct Answer:  A. DatabaseMetaData interface
EXPLANATION

DatabaseMetaData (obtained from Connection.getMetaData()) provides information about the entire database like tables, columns, keys, and supported features.

Take Test
Q.267 Hard JDBC
A query execution takes 5 seconds consistently. Which JDBC optimization technique should NOT be used for this scenario?
A Connection pooling
B Batch processing for multiple inserts
C Using indexes on frequently queried columns
D Increasing setFetchSize() value
Correct Answer:  D. Increasing setFetchSize() value
EXPLANATION

If query execution itself is slow (5 seconds), the bottleneck is in database operations, not data transfer. Increasing setFetchSize() only optimizes data retrieval, not query execution.

Take Test
Q.268 Medium JDBC
What is the correct way to handle resource management in JDBC with Java 7+?
A try-catch-finally blocks with explicit close()
B try-with-resources statement (try-with parentheses)
C Using finally blocks only
D Automatic garbage collection handles it
Correct Answer:  B. try-with-resources statement (try-with parentheses)
EXPLANATION

try-with-resources automatically closes AutoCloseable resources (Connection, Statement, ResultSet), preventing connection leaks elegantly.

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