Professional Documents
Culture Documents
Learn how to deploy, use, and benchmark JDBC driver types 1, 2, 3, and 4
Summary In this article, we'll examine the basic architecture of the four different types of JDBC drivers and enumerate their pros and cons. In addition, we'll evaluate and compare five specific industry-standard drivers in terms of database access time, connection time, type of driver, and so forth. The drivers taken for comparison include JDBCODBC Bridge, IDS Driver, MERANT's SequeLink, JTurbo by Ashna, and I-net Sprinta 2000. Step-by-step instructions are given to deploy and use these drivers. (3,000 words) By Nitin Nanda
Why should you consider Java Database Connectivity (JDBC) drivers apart from the
JDBC-ODBC Bridge? What level of JDBC driver is suited for your application? What parameters should you use for evaluating a JDBC driver? This article evaluates various JDBC drivers and answers these questions. While writing JDBC applications, developers generally start with JDBC-ODBCBridge to connect to databases. But when an application reaches some advanced stage, for example, when it needs to support multithreading, the JDBC-ODBCBridge poses a few problems. So, the need arises for a robust JDBC driver. In that case, the type of driver depends on quite a few parameters: whether the application is Internet or intranet based, whether it needs to support heterogeneous databases, the number of concurrent users, and so on. In the first section of this article, we'll look at the basic architecture underlying the four JDBC driver types and enumerate the pros and cons for choosing one type over another -- information you can use to decide what type of JDBC drivers will be best suited for your specific application. In the second section, we'll see evaluations of five specific industry-standard drivers: Sun's JDBC-ODBC Bridge, IDS Software's IDS Driver, Ashna's JTurbo, I-net Software's I-net Sprinta, and MERANT's SequeLink. I have also provided the steps required to evaluate each driver, as well as code snippets for specifying the classpath, loading the driver, establishing a database connection, and retrieving and inserting records. You may find it useful to use the code snippets provided in your evaluation program and follow these steps to determine benchmarks suited to your software and hardware requirements.
Pros The JDBC-ODBC Bridge allows access to almost any database, since the database's ODBC drivers are already available. Type 1 drivers may be useful for those companies that have an ODBC driver already installed on client machines. Cons The performance is degraded since the JDBC call goes through the bridge to the ODBC driver, then to the native database connectivity interface. The result comes back through the reverse process. Considering the performance issue, type 1 drivers may not be suitable for large-scale applications. The ODBC driver and native connectivity interface must already be installed on the client machine. Thus any advantage of using Java applets in an intranet environment is lost, since the deployment problems of traditional applications remain.
Pros Type 2 drivers typically offer significantly better performance than the JDBC-ODBC Bridge. Cons The vendor database library needs to be loaded on each client machine. Consequently, type 2 drivers cannot be used for the Internet. Type 2 drivers show lower performance than type 3 and type 4 drivers.
Pros The net-protocol/all-Java driver is server-based, so there is no need for any vendor database library to be present on client machines. Further, there are many opportunities to optimize portability, performance, and scalability. Moreover, the net protocol can be designed to make the client JDBC driver very small and fast to load. Additionally, a type 3 driver typically provides support for features such as caching (connections, query results, and so on), load balancing, and advanced system administration such as logging and auditing. Cons Type 3 drivers require database-specific coding to be done in the middle tier. Additionally, traversing the recordset may take longer, since the data comes through the backend server.
completely implemented in Java to achieve platform independence and eliminate deployment administration issues.
Pros Since type 4 JDBC drivers don't have to translate database requests to ODBC or a native connectivity interface or to pass the request on to another server, performance is typically quite good. Moreover, the native-protocol/all-Java driver boasts better performance than types 1 and 2. Also, there's no need to install special software on the client or server. Further, these drivers can be downloaded dynamically. Cons With type 4 drivers, the user needs a different driver for each database.
1. 2. 3. 4. 5.
JDBC-ODBC Bridge by Sun IDS Driver by IDS Software SequeLink by MERANT JTurbo 1.22 by Ashna I-net Sprinta 2000 by I-net Software
JDBC
Fetch & traversal time (ms) (33,000 records) Data insertion time (ms) (1,000 records)
865
3,700
3,000
3,500
3,600
3,050
The database table on which the tests have been performed has columns: int, varchar(255), and datetime. The test conditions were as follows:
Test conditions
Platform: Computer with Java VM: SQL Server 7.0: JVM: Windows NT 4.0 Pentium III Pentium III JDK 1.2.1
Table 2. Test conditions
Now let's look at the description of these drivers and the general settings required to evaluate them.
JDBC-ODBC Bridge
The JDBC-ODBC Bridge by Sun's JavaSoft -- a type 1 driver -- results from a joint effort between JavaSoft and MERANT. Available in the Java Developer Kit (JDK), this product leverages the large number of ODBC drivers available and has provided some momentum for JDBC to become widely accepted in a short time frame. Follow these steps to evaluate it:
Using the Windows Control Panel, create an ODBC DSN (data source name) for the database. Load the driver In a JDBC program, one of the first things to do is to load the JDBC driver by calling the forName() static method of the Class class. forName() takes one string parameter: the name of the driver along with its package. For JavaSoft's JDBC-ODBC Bridge, this string is "sun.jdbc.odbc.JdbcOdbcDriver". Therefore, the call would look like:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
jdbc:<subprotocol>:<subname>
A connection to the database could be established in this manner:
String stUrl_= "jdbc:odbc:myDSN"; // let's say myDSN // is the name of ODBC DSN Connection connection_ = DriverManager.getConnection(stUrl_, "sa", "");
The following code could be used to calculate the database connection time:
//set up connection to a specified database String stUrl_= "jdbc:odbc:myDSN"; connection_ = DriverManager.getConnection(stUrl_,"sa",""); java.util.Date dEnd = new java.util.Date(); //get end time
//get time difference, which is time taken for connection ldiff = dEnd.getTime()-dStart.getTime();
Conclusion The JDBC-ODBC Bridge is a good starting point for learning JDBC. However, it should be considered a transitional solution, since it is not suitable for large-scale applications.
You'll have to install the IDS Server on the server machine and run it. The IDS Server runs as a service on the server machine. Create an ODBC DSN Create an ODBC DSN for the database on the machine where the IDS Server is running. Set the classpath Install the IDS Driver on the client machine. The classpath setting must include the IDS Driver. It can be set in the command prompt by executing the following command:
For the IDS Driver, the parameter to the forName() method is "ids.sql.IDSDriver". The call would look like:
Class.forName("ids.sql.IDSDriver");
jdbc:<subprotocol>:<subname>
For the IDS Driver, the <subprotocol> is ids. The <subname> portion of the URL identifies the database to connect to, as well as the name of the server where the IDS Server is running. The <subname> is formulated by using the following pattern:
host_address/conn?dbms=odbc&dsn='data source' // Here, host_address is the IP address and port // number of the installed IDS Server, for example, // www.foo.com:12.
A connection to the database could be established in this manner:
stUrl_="jdbc:ids://myServer:12/conn?dsn='myDSN'"; Connection connection_ = DriverManager.getConnection(stUrl_, "sa", ""); // Let's say myDSN is the name of the ODBC DSN // and myServer the server that where IDS Server is installed.
The following code could be used to calculate the data access time. The complete result set is traversed in this case:
Statement statement_ = connection_.createStatement(); long ldiff; java.util.Date dStart = new java.util.Date(); //get start time ResultSet rs = statement_.executeQuery("SELECT * FROM myTable"); //execute query while(rs.next()); // traverse the whole record set java.util.Date dEnd = new java.util.Date(); //get end time ldiff = dEnd.getTime()-dStart.getTime(); //get time difference statement_.close();
Conclusion The IDS Driver is a good option because of its small size, low price, and good performance.
Class.forName("com.merant.sequelink.jdbc.SequeLinkDriver");
Here, host_address is the IP address of the machine where the SequeLink server is running, and port number is the port of the installed SequeLink Server (for example, www.foo.com:12). A connection to the database could be established in this manner:
"jdbc:sequelink://myServer:4006;databaseName=myDb"; // Let's say myDb is the name of the database in SQL Server // and myServer is the server where SequeLink Server is installed.
5. Calculate parameters
Parameters such as database connection time, data access time, and record insertion time can be calculated for SequeLink using the code snippets provided in the preceding sections.
Conclusion SequeLink is suitable for organizations with several concurrent clients and heterogeneous databases. In such a scenario, it is a better solution than using several DBMS-specific and thin-client JDBC drivers.
JTurbo comes as a JTurbo.jar file that must be present in the client machine's classpath. It can be set in the command prompt by executing the following command:
For JTurbo, the parameter for the forName() method is "com.ashna.jturbo.driver.Driver". The call would look like:
Class.forName("com.ashna.jturbo.driver.Driver");
jdbc:<subprotocol>:<subname>
For the JTurbo JDBC driver, the <subprotocol> is JTurbo. The <subname> portion of the URL identifies the database to connect to, as well as the name of the server where the database resides. The <subname> is formulated using the following pattern:
4. Calculate parameters
The following code could be used to calculate the data access time. The result set is not traversed in this case:
Statement statement_ = connection_.createStatement(); long ldiff; java.util.Date dStart = new java.util.Date(); //get start time ResultSet rs = statement_.executeQuery("SELECT * FROM myTable"); //execute query java.util.Date dEnd = new java.util.Date(); //get end time ldiff = dEnd.getTime()-dStart.getTime(); //get time difference statement_.close();
Conclusion The JTurbo JDBC driver provides Java developers with an interface to MS SQL Server. As a type 4 driver, it provides a high level of performance with platform independence. It supports the development of Java applets with no client-side platform dependencies.
For I-net Sprinta 2000, the parameter to the forName() method is "com.inet.tds.TdsDriver". The call would look like:
Class.forName("com.inet.tds.TdsDriver");
jdbc:<subprotocol>:<subname>
For this driver, the <subprotocol> is inetdae. The <subname> portion of the URL identifies the database to connect to, as well as the name of the server where the database resides. The <subname> portion is formulated using the following pattern:
jdbc:inetdae:hostname:portnumber?database=MyDb
A connection to the database could be established in this manner:
stUrl_="jdbc:inetdae:myServer:1433?database=myDatabase"; // Let's say myDatabase is the name of the database // and myServer the server that has the database Connection connection_ = DriverManager.getConnection(stUrl_, "sa", "");
The following code could be used to calculate the average time taken to insert database records. The table where the records are inserted has the following columns: int, varchar(255), and datetime:
Statement statement_ = connection_.createStatement(); long ldiff; SimpleDateFormat sFormat = new SimpleDateFormat("dd-MMMMyyyy HH:mm:ss:SSS"); java.util.Date dStart = new java.util.Date(); //get start time for(int i=0;i<1000;i++) { String sDate = sFormat.format(new java.util.Date()); String stInsert="INSERT INTO test VALUES ("+i+",'"+i+"', '" +sDate+"')"; Statement_.execute(stInsert); } java.util.Date dEnd=new java.util.Date(); //get end time ldiff=dEnd.getTime() - dStart.getTime(); //get difference
Conclusion The I-net Sprinta 2000, which can be dynamically downloaded, does not require you to install special software on the client or server. Hence, it's a good solution for Internet applications.
Conclusion
The JDBC-ODBC Bridge should be considered only a transitional solution. For largescale applications you should consider one of the type 2, type 3, or type 4 drivers. For intranet applications it would be useful to consider type 2 drivers. But since type 3 and type 4 drivers show significantly better performance than type 2 drivers and the trend is towards development of more robust pure-Java drivers, it might be useful to evaluate type 3 or type 4 for intranet situations too. For Internet-related applications, there is no option but to use type 3 or type 4 drivers. Type 3 drivers are best suited for environments that need to provide connectivity to a variety of DBMS servers and heterogeneous databases and that require significantly high levels of concurrently connected users where performance and scalability are major concerns. Type 4 drivers are generally aimed at the workgroup level.
About the author Nitin Nanda works as a team leader at Quark's India R&D center. He is responsible for the design and development of a three-tier product being engineered in Java with RMI-IIOP as the distributed protocol. Before Quark, he worked with Cadence Design Systems as a senior member of the technical staff.