JDBC / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 […]
JDBC / NOTES</>↗JDBC12 Feb 2026
To configure c3p0 as a JDBC connection pool, you typically: create a DataSource (usually ComboPooledDataSource) tune pool parameters (min/max pool size, idle time, timeouts, statement cache) use the DataSource everywhere instead of DriverManager.getConnection(…) close Connection/Statement/ResultSet normally (c3p0 returns connections to the pool on close()) Below are the common ways to do it. 1) Programmatic configuration […]
JDBC / NOTES</>↗JDBC12 Feb 2026
To configure an Apache DBCP connection pool for “plain” JDBC, you typically create a pooled DataSource once at startup, then get connections from it (and always close them to return to the pool). Below are the two most common approaches. 1) Recommended (DBCP2): BasicDataSource (simplest) Create and configure the pool package org.kodejava.jdbc; import org.apache.commons.dbcp2.BasicDataSource; import […]