Govt. Exams
Entrance Exams
JDBC Connections are not thread-safe. Each thread must have its own Connection to prevent concurrent access issues and data corruption.
Try-with-resources (try-with-resources statement) automatically closes AutoCloseable resources, preventing memory leaks.
Closing a Statement typically invalidates its associated ResultSet in most JDBC drivers, though behavior may vary.
Unclosed connections remain allocated, eventually exhausting the connection pool and causing application failures.
A SavePoint allows you to roll back part of a transaction without rolling back the entire transaction. You can create nested transactions by setting multiple savepoints and rolling back to specific ones.
executeBatch() returns an int array where each element represents the update count for the corresponding statement. A value of -3 (Statement.EXECUTE_FAILED) indicates failure for that statement.
The wasNull() method checks if the last value retrieved from a CallableStatement was NULL. To get the return value, you typically use getInt(), getString(), etc., and then check wasNull().
The default isolation level depends on the specific database and JDBC driver configuration. Different databases have different defaults (MySQL is REPEATABLE_READ, Oracle is READ_COMMITTED).
PreparedStatement with parameterized queries is the most secure approach as it separates SQL logic from data. The database treats parameters as data, not executable code, preventing SQL injection.
update*() methods (like updateInt(), updateString()) modify individual column values in the current row, while updateRow() commits all these changes to the database.