220.127.116.11. JDBC: Working with relational databases
JDBC (JSR 054) is the Java API for working with relational database systems. JDBC allows
a Java program to send SQL query and update statements to a database server and to
retrieve and iterate through query results returned by the server. JDBC also allows you to
get metadata about the database and its tables from the database server.
The JDBC API is independent of vendor-specific APIs defined by particular database
systems. The JDBC architecture relies upon a Driver class that hides the details of
communicating with a database server. Each database server product requires a custom
Driver implementation to allow Java programs to communicate with it. Major database
vendors have made JDBC drivers available for their products. In addition, a "bridge" driver
exists to enable Java programs to communicate with databases through existing ODBC
The JDBC API is found in the java.sql package, which was first introduced in Java 1.1.
Java 1.2 updated the core APIs to include JDBC 2.0, which added a number of new classes
to support advanced database features. JDBC 2.0 also provides additional features in the
javax.sql standard extension package. JDBC includes classes for extracting data from
databases in the form of Java objects, for pooling database connections, and for obtaining
database connection information from a JNDI name service. The extension package also
supports scrollable result sets, batch updates, and the storage of Java objects in databases.
The latest versions of the J2SE, 1.4 and 5.0, include the JDBC 3.0 API, whose specification
was released in February 2002. This version of JDBC adds support for transaction
"savepoints," allowing you to programmatically roll back database transactions to multiple
checkpoints, as well as some enhancements to connection pooling support. At this writing,
however, driver support for JDBC 3.0 is still somewhat limited, and in several cases you
may have only JDBC 2.x API support in your drivers.
The JDBC API is simple and well designed. Programmers who are familiar with SQL and
database programming in general should find working with databases in Java very easy.
See Chapter 8 for a tutorial on JDBC and Appendix D for a quick reference to SQL.