To access a database management system (DBMS) in Java, you need a JDBC (Java Database Connectivity) driver. You may write such drivers, which range from types 1 to 4, in pure Java or a combination of Java and Java Native Interface (JNI) methods. The industry trend is towards the more robust types 3 and 4 pure-Java drivers. Type 3 drivers shine when supporting Internet deployment in environments that connect to a variety of DBMS servers requiring numerous concurrently connected users where performance and scalability are major concerns. Therefore, to develop a high-performance, Internet-deployable application, you'll often find it useful to convert your existing type 1 or 2 drivers to type 3 drivers.
| Read the whole series |
|---|
In this three-part series, we first introduce our own type 3 JDBC driver's architecture and design (Part 1), then show how to implement and deploy the driver (Part 2), and finish by explaining how you can add advanced features to the driver, like SQL logging or connection pooling (Part 3).
Note: Before you read this article, you may wish to read Nitin Nanda's "JDBC Drivers in the Wild" (JavaWorld, July 2000) to better understand JDBC drivers.
JDBC provides a programming-level interface for uniformly communicating with databases. To use the JDBC API with a particular DBMS, you need a JDBC driver to mediate between JDBC technology and the database. JDBC drivers divide into four types or levels. Each type defines a JDBC driver implementation with increasingly higher levels of platform independence, performance, and deployment administration. The four types are:
All JDBC drivers implement the four important JDBC classes: Driver, Connection, Statement, and ResultSet. The DriverManager class included with the java.sql package tracks the loaded JDBC drivers. The client application retrieves the desired database connections through the DriverManager class. The JDBC Driver class loads whenever a call comes to the driver:
Class.forName("com.jw.client.JWDriver");
The specified JDBC driver's static code block runs during the JDBC driver class's loading, which registers the driver with
the DriverManager. Now, whenever a client program retrieves a database connection with the DriverManager.getConnection() method, the DriverManager in turn calls the Driver.connect() method. Every JDBC driver must implement the java.sql.Driver interface. So, the JDBC driver's connect() method checks whether the driver URL is correct, then returns the Connection within its connect() method.
To show you a type 3 driver's inner workings, we've constructed our own type 3 JDBC driver for this series. As Figure 1 shows, our JDBC type 3 driver—the network-protocol/all-Java driver—follows a three-tiered approach, whereby the JDBC database requests pass through the network to the middle-tier server. The middle-tier server then translates the requests (directly or indirectly) to the database-specific native-connectivity interface to further the request to the database server. The middle-tier server, written in Java, accesses the database server with a type 1 JDBC-ODBC Bridge driver.
exampleBy Anonymous on March 31, 2009, 5:19 ami need how to simple jdbc application using four types of drivers.
Reply | Read entire comment
View all comments