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.
Advertisement
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.
What exception is thrown when a database connection fails in JDBC?
SQLException is thrown when database-related errors occur, including connection failures and SQL execution errors.
In JDBC, what does the executeQuery() method return?
executeQuery() returns a ResultSet containing the rows fetched from the database for SELECT queries.
What is the purpose of Connection.commit() in JDBC?
commit() saves all changes made during the current transaction permanently to the database.
Which JDBC method executes UPDATE, INSERT, or DELETE statements?
executeUpdate() executes DML statements and returns the number of rows affected.
What is the benefit of using PreparedStatement over Statement for repeated queries?
PreparedStatement offers both pre-compilation for performance and SQL injection prevention through parameterized queries.
What does ResultSetMetaData.getColumnCount() return?
getColumnCount() returns the total number of columns present in the ResultSet.
In JDBC, which class is used to retrieve database metadata information?
DatabaseMetaData provides information about the database, tables, columns, and other database properties.