What does the DriverManager.getConnection() method return?
DriverManager.getConnection() establishes a connection to the database and returns a Connection object.
In JDBC, which exception is thrown when the database driver class is not found?
ClassNotFoundException is thrown when Class.forName() cannot locate the JDBC driver class.
What is the purpose of the Connection.commit() method in JDBC?
commit() finalizes the transaction and persists all changes made since the last commit or rollback.
Which JDBC method is used to retrieve metadata information about the database?
Connection.getMetaData() returns a DatabaseMetaData object containing information about the database and driver.
In a JDBC batch operation, what does executeBatch() return?
executeBatch() returns an int array where each element represents the number of rows affected by each statement in the batch.
Advertisement
What is the difference between ResultSet.TYPE_SCROLL_INSENSITIVE and ResultSet.TYPE_SCROLL_SENSITIVE?
TYPE_SCROLL_INSENSITIVE doesn't reflect concurrent database changes, while TYPE_SCROLL_SENSITIVE may reflect such changes.
Which JDBC method is used to set an input parameter in a PreparedStatement?
PreparedStatement uses type-specific setter methods like setInt(), setString(), setDate() to bind parameters.
What happens when Connection.setAutoCommit(false) is called in JDBC?
Setting autoCommit to false enables manual transaction management where commit() must be explicitly called.
In JDBC, what is the purpose of the ResultSetMetaData interface?
ResultSetMetaData provides information about columns, data types, and column properties of a ResultSet.
Which JDBC constant specifies read-only access for a ResultSet?
CONCUR_READ_ONLY is the concurrency constant that specifies a read-only ResultSet.
What is Connection pooling in JDBC and why is it used?
Connection pooling maintains a pool of reusable connections, reducing the cost of creating new connections repeatedly.
In JDBC, what is the purpose of CallableStatement?
CallableStatement is used to call stored procedures and stored functions in the database.
A developer creates a JDBC connection but forgets to close it. What might be the consequence?
Unclosed connections remain allocated, eventually exhausting the connection pool and causing application failures.
Consider a scenario where a developer retrieves a ResultSet and then closes the Statement object. What happens to the ResultSet?
Closing a Statement typically invalidates its associated ResultSet in most JDBC drivers, though behavior may vary.
What is the optimal approach to handle JDBC resources to prevent memory leaks in a production application?
Try-with-resources (try-with-resources statement) automatically closes AutoCloseable resources, preventing memory leaks.
In a multi-threaded JDBC application, why should each thread have its own Connection object?
JDBC Connections are not thread-safe. Each thread must have its own Connection to prevent concurrent access issues and data corruption.
Which interface in JDBC is used to execute SQL queries and retrieve results?
Statement interface is used to execute SQL queries. Connection creates statements, ResultSet holds results, and Driver manages connections.
Which JDBC API is used to execute parameterized queries safely?
PreparedStatement allows parameterized queries using placeholders (?) and prevents SQL injection attacks.
What is the correct syntax to load a JDBC driver in Java?
Class.forName() is the standard way to load JDBC drivers. It dynamically loads the driver class.
Which method is used to retrieve the next row from a ResultSet?
The next() method moves the cursor to the next row in the ResultSet and returns true if a row exists.