JDBC 3.0
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 driverThe 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 driverConverts 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