JDBC 3.0


Contents

  1. Overview
  2. SQLJ Spec
  3. Java Blend
  4. Two-tier and Three-tier
  5. JDBC drivers
  6. Java-relational DBMSs
  7. Links

See Also

  1. Connection
  2. Driver Manager
  3. Statement
  4. callablestatement
  5. preparedstatement
  6. SimpleSelect
  7. ResultSet
  8. Mapping
  9. Bridge
  10. Asynchronous
  11. Connections
  12. Cursors
  13. Dynamic Database
  14. JDBC API
  15. Mapping SQL
  16. Passing Parameters
  17. ResultSet Example
  18. Security
  19. SQL Extensions
  20. Update Example
  21. Variants
  22. Batch Updates
  23. Custom SQL Types
  24. Persistence


Overview

The JDBC 3.0 API consists of the java.sql and javax.sql packages, which are part of the Java 2 Platform, Standard Edition, Version 1.4 (J2SE), and are used to connect to and query databases.

To use the JDBC API with a particular database management system requires a JDBC driver. Note that the SDK includes a JDBC-ODBC Bridge driver which can be used for development purposes, but is inapproprate for production systems.

Here is some code that uses a driver to establish a connection with a data source, send a query, and process the results:

Connection con = DriverManager.getConnection("jdbc:DriverName:Database", "login", "password");
Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");

while (rs.next()) 
{
    int x = rs.getInt("a");
    String s = rs.getString("b");
    float f = rs.getFloat("c");
}

SQLJ Spec

The SQLJ specification provides an embedded SQL preprocessor that allows a programmer the intermixing of SQL statements with Java statements. For example, a Java variable can be used in an SQL statement to receive or provide SQL values. The SQLJ preprocessor effectively translates this Java/SQL mix into the Java programming language with JDBC calls.

Java Blend

Java Blend provides a direct mapping of relational database tables to Java classes. The table becomes a class. Each row of the table becomes an instance of the class. Each column value corresponds to an attribute of that instance. SQL calls to fetch and store data are automatically generated "beneath the covers."

Two-tier and Three-tier

In two-tier models, a Java applet or application talks directly to the data source. This requires a JDBC driver that can communicate with the particular data source being accessed.

In three-tier models, commands are sent to a "middle tier" of services, which then sends the commands to the data source. The data source processes the commands and sends the results back to the middle tier, which then sends them to the user.


JDBC drivers

JDBC-ODBC bridge
+ an ODBC driver
The Java Software bridge product provides JDBC access via ODBC drivers. The ODBC must be installed on each client machine that uses the JDBC-ODBC driver.
Native-API part Java driver Converts JDBC calls into calls on the client API for various databases, such as Oracle, DB2, and Sybase. Like the bridge driver, this type of driver requires that some OS specific binary code be loaded on each client machine.
Native-protocol
pure Java driver
Converts JDBC calls into the network protocol used by a DBMS. Generally developed by database vendor
JDBC-Net pure Java driver Middleware that converts JDBC into internetworking protocols


Links

  1. Getting Started
  2. Specifications
  3. Basic Tutorial
  4. Advanced Tutorial
  5. Rowset Tutorial
  6. FAQ
  7. Using Blob objects
  8. Using Clob objects
  9. JDBC API Tutorial
  10. Java 2 SDK, Enterprise Edition Documentation
  11. JDBC API Home page