What is the primary advantage of using PreparedStatement over Statement?
Answer: A
PreparedStatement offers faster execution due to precompilation and prevents SQL injection through parameterized queries using placeholders (?).
Q.602Medium
Which method must be called to move cursor to the next row in ResultSet?
Answer: A
The next() method moves the ResultSet cursor to the next row and returns true if a row exists, false if no more rows. It's essential for iterating through results.
Q.603Medium
What is Connection pooling in JDBC?
Answer: A
Connection pooling maintains a pool of reusable database connections to improve performance and reduce overhead of creating new connections repeatedly.
Q.604Medium
Which DriverManager method is used to establish a database connection?
Answer: B
DriverManager.getConnection() is the standard method that takes URL, username, and password to establish a connection to the database.
Q.605Medium
What does the setAutoCommit(false) method do in JDBC?
Answer: A
setAutoCommit(false) disables automatic commit, allowing multiple statements to be part of single transaction. Manual commit() or rollback() must be called.
Advertisement
Q.606Hard
Consider code: String query = "SELECT * FROM users WHERE id=" + userId; stmt.executeQuery(query); What security issue exists?
Answer: B
This is vulnerable to SQL injection as user input is directly concatenated. Using PreparedStatement with parameters prevents this: "SELECT * FROM users WHERE id=?"
Q.607Hard
How would you implement batch processing in JDBC for multiple INSERT operations?
Answer: A
addBatch() adds SQL command to batch, executeBatch() executes all batched commands at once, improving performance significantly for multiple operations.
Q.608Hard
What is the difference between execute(), executeQuery(), and executeUpdate()?
Answer: A
execute() returns boolean (true if ResultSet available), executeQuery() returns ResultSet for SELECT, executeUpdate() returns row count for INSERT/UPDATE/DELETE.
Q.609Hard
Which JDBC feature allows you to call stored procedures?
Answer: C
CallableStatement is used to invoke stored procedures and functions. It extends PreparedStatement and supports IN, OUT, and INOUT parameters.
Q.610Hard
In JDBC, what does the ResultSet.TYPE_SCROLL_INSENSITIVE constant represent?
Answer: B
TYPE_SCROLL_INSENSITIVE creates scrollable ResultSet (can move forward/backward) but changes made to database after ResultSet creation are not reflected.
Q.611Medium
Which of the following is the correct way to close JDBC resources to prevent resource leaks?
Answer: D
Resources should be closed in reverse order of creation (ResultSet → Statement → Connection), or preferably using try-with-resources which auto-closes resources.
Q.612Easy
Which JDBC driver type is platform-independent and does not require native code installation?
Answer: D
Type 4 drivers (thin drivers) are pure Java drivers that communicate directly with the database using the database native protocol. They are platform-independent and do not require native code.
Q.613Easy
What is the correct syntax to retrieve an integer value from a ResultSet object at column index 2?
Answer: A
The correct method is getInt(int columnIndex) which retrieves an integer value from the ResultSet at the specified column index (1-based indexing).
Q.614Easy
Which interface represents a single row of data retrieved from a database in JDBC?
Answer: B
ResultSet interface represents the result set of a query. It contains the data returned from a database query and provides methods to access and traverse through the rows.
Q.615Medium
What does the PreparedStatement interface provide that Statement does not?
Answer: D
PreparedStatement provides both parameterized queries (preventing SQL injection) and precompilation of SQL statements, resulting in better security and performance compared to Statement.
Q.616Easy
In JDBC, what is the purpose of the Class.forName() method?
Answer: A
Class.forName() is used to load the JDBC driver class dynamically and register it with the DriverManager. For example: Class.forName("com.mysql.cj.jdbc.Driver");
Q.617Medium
Which exception is thrown when a database operation violates a unique constraint in JDBC?
Answer: D
SQLIntegrityConstraintViolationException is a specific subclass of SQLException that is thrown when integrity constraint violations occur, such as unique constraint violations.
Q.618Medium
What is the correct way to use try-with-resources for JDBC operations?
Answer: A
The try-with-resources statement automatically closes resources implementing AutoCloseable. Since Connection implements AutoCloseable, it will be automatically closed.
Q.619Medium
Which method is used to retrieve metadata about the database in JDBC?
Answer: B
The getDatabaseMetaData() method is called on a Connection object to retrieve DatabaseMetaData information about the database, such as table names, column information, etc.
Q.620Medium
In JDBC, what does the ResultSet.absolute(5) method do?
Answer: B
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.