How do Java applications interact with relational databases in a portable way, without being tied to specific database products?
JDBC (Java Database Connectivity) is a standard Java API that provides universal database access. Applications use the JDBC API, while database-specific JDBC drivers handle the actual communication with each database.
- Application uses JDBC API to issue SQL statements
- JDBC Driver Manager selects the appropriate driver for the database
- Driver translates JDBC calls to database-specific protocol
- Results are returned through standard JDBC result sets
- Part of Java SE standard edition
- Drivers for all major databases (MySQL, Oracle, PostgreSQL, etc.)
- Supports connection pooling through DataSource
- SQL statements via Statement, PreparedStatement, CallableStatement
- Built from: Bean-Managed Persistence
- Related: ejbLoad(), ejbStore(), ejbCreate(), ejbRemove()
- Related: Session Bean Relationships, One-to-One Relationship
- Must close connections, statements, and result sets properly
- Use PreparedStatement to prevent SQL injection