JDBC / CATATAN</>↗JDBC22 Mar 2026
You use java.sql.DatabaseMetaData by: Opening a Connection Calling conn.getMetaData() Querying catalogs/schemas/tables/columns/keys/indexes via the DatabaseMetaData “getXxx” methods (they mostly return ResultSets) Reading those result sets like normal query results Below are the most common inspection tasks and the JDBC calls that power them. 1) Get the DatabaseMetaData package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.Dr...
JDBC / CATATAN</>↗JDBC26 Feb 2026
In JDBC, “database timeouts” can mean a few different things, and you handle each at a different layer. The most practical approach is to set timeouts deliberately and then catch the right exception types so you can decide whether to retry, fail fast, or surface a user-friendly error. 1) Connection timeout (can’t connect / handshake […]
JDBC / CATATAN</>↗JDBC23 Feb 2026
Deadlocks in JDBC typically refer to database-level deadlocks, where two or more transactions block each other while waiting for locks on resources (e.g., rows or tables). JDBC itself doesn’t “detect” them proactively; instead, the database server signals them via exceptions. Here’s how to handle detection effectively: 1. Catch and Inspect SQLException Wrap your JDBC operations […]
JDBC / CATATAN</>↗JDBC23 Feb 2026
SQLState error codes are a standardized way in JDBC to categorize database errors, making it easier to handle exceptions programmatically. They’re part of the SQLException class and follow the SQL:2003 standard (like “23000” for integrity constraints). Unlike vendor-specific error codes (from getErrorCode()), SQLState is more portable across databases. 1. What is SQLState? It’s a 5-character […]
JDBC / CATATAN</>↗JDBC19 Feb 2026
For MySQL (mysql-connector-j), “proper” SQLException handling is the same core approach as JDBC in general, plus a few MySQL-specific signals (SQLState + error code) that are worth using for translation/retry decisions. 1) Keep the important diagnostics (MySQL error code + SQLState) MySQL gives you two invaluable fields: e.getErrorCode() → MySQL vendor error code (e.g., 1062 […]
JDBC / CATATAN</>↗JDBC18 Feb 2026
Handling SQLException “properly” in JDBC is mostly about (1) not leaking resources, (2) preserving diagnostic detail, (3) rolling back safely, and (4) translating errors into something meaningful at your app boundary. 1) Always close JDBC resources (use try-with-resources) This eliminates most error-handling bugs (leaks and double-closes), and it also handles exceptions thrown during close() by […]