DB2 Driver type

  General description of 

  IBM's database product line to provide different versions of the data access API can be said to be many, including the early drive on the CLI, the most recent of pure Java driver and CLI and the combination of Java. For a specific version of DB2 Driving a specific driver has a common drive, it is clear, however, many versions of the database system and various versions of the access to the drive, on the face of customers, the relationship between them seemed ever. So in The use of IBM's database product, in the minds must pay attention to the corresponding versions of GM and select the appropriate drive. Fortunately, IBM has begun to move toward reunification, have begun to pay attention to the ease of use, these efforts from the DB2 UDB V7 started. Since then, in accordance with the Java area of the type of JDBC driver, IBM has driven the three categories. 

  DB2's JDBC TYPE 2 driver so that Java applications through JDBC calls DB2. On DB2 JDBC type 2 driver of the call is converted into the local method of Java. Java driver of the use of such applications must be running in a DB2 client on, JDBC Through this request to DB2 client server. In the use of DB2 JDBC application drivers visit DB2 UDB for iSeries data sources or DB2 for OS/390 or z / OS environment in the data sources, must be installed DB2 Connect Version 8. DB2 JDBC type 2 driver support JDBC 1.2 norms described in the most JDBC and SQLJ function, and supports JDBC 2.0 norms described in some function. 

  DB2's JDBC TYPE 3 driver, also known as applet or net driver, it JDBC from a client and a JDBC server (the process name is db2jd) components. Applet can be used in the application can also be in使用. 

  DB2's JDBC TYPE 4 driver known as the generic driver, is pure Java to achieve, the drive also supports SQLJ. 

  IBM currently has no TYPE 1 of the JDBC driver. 

  Drivers of these types of packages is: db2jcc.jar and sqlj.zip documents, sqllib \ bin \ db2jcct2.dll (the document is necessary for TYPE2). 

  Use 

  In the use of JDBC connection DB2 UDB V7.2 and DB2 UDB V8.1, if encountered some puzzling problems, can check the development environment to use the JDK, in the IBM JDK known in the switch (currently 1.3 and Version 1.4), often you will be able to solve the problem. 

  DB2 UDB V8.2 personal version, the following test code test three connections, and gives the results: 

  import java.sql .*; 

  public class Employee ( 

  / ** 
  * @ Param args 
  * / 
  public static void main (String [] args) ( 
  / / TODO Auto-generated method stub 
  Employee ee = new Employee (); 
  try ( 
  ee.testJcc ();// success 
  ee.testNet ();// success 
  ee.testApp ();// failure, why is: type 2 need to install the DB2 client visits, tests had not been installed. If type-2 Remote Access database can be remote database cataloging to the local ready. 
  ) Catch (Exception e) ( 
  e.printStackTrace (); 
  ) 
  ) 

  / ** 
  * Test driver architecture for the type 4 driver: com.ibm.db2.jcc.DB2Driver, the driver of the package db2jcc.jar. 
*
  * @ Throws InstantiationException 
  * @ Throws IllegalAccessException 
  * @ Throws ClassNotFoundException 
  * @ Throws SQLException 
  * / 
  public void testJcc () throws InstantiationException, 
  IllegalAccessException, ClassNotFoundException, SQLException ( 
  Class.forName ( "com.ibm.db2.jcc.DB2Driver"). NewInstance (); 
  String url = "jdbc: db2: / / 192.168.0.17:50000 / SAMPLE"; 
  Connection con = DriverManager.getConnection (url, "db2admin", "cherub"); 
  con.setAutoCommit (false); 
  Statement stmt = con.createStatement (); 
  ResultSet rs = stmt.executeQuery ( "select * from Employee"); 
  while (rs.next ()) ( 
  System.out.println (rs.getString (1) + "," + rs.getString (2)); 
  ) 
  ) 

  / ** 
  * Test driver architecture for the three types of driver: COM.ibm.db2.jdbc.net.DB2Driver, the drive in the db2java.zip in the package. 
*
  * @ Throws InstantiationException 
  * @ Throws IllegalAccessException 
  * @ Throws ClassNotFoundException 
  * @ Throws SQLException 
  * / 
  public void testNet () throws InstantiationException, 
  IllegalAccessException, ClassNotFoundException, SQLException ( 
  Class.forName ( "COM.ibm.db2.jdbc.net.DB2Driver"). NewInstance (); 
  / / Interception of the target DB2 system default port services in 6789, it also needs the URL Pattern objectives specified in the port, 
  String url = "jdbc: db2: 192.168.0.17: SAMPLE"; 
  Connection con = DriverManager.getConnection (url, "db2admin", "cherub"); 
  con.setAutoCommit (false); 
  Statement stmt = con.createStatement (); 
  ResultSet rs = stmt.executeQuery ( "select * from Employee"); 
  while (rs.next ()) ( 
  System.out.println (rs.getString (1) + "," + rs.getString (2)); 
  ) 
  ) 

  / ** 
  * Test driver architecture for the type 2 driver: COM.ibm.db2.jdbc.app.DB2Driver, also located in the driver package in the db2java.zip. 
*
  * @ Throws InstantiationException 
  * @ Throws IllegalAccessException 
  * @ Throws ClassNotFoundException 
  * @ Throws SQLException 
  * / 
  public void testApp () throws InstantiationException, 
  IllegalAccessException, ClassNotFoundException, SQLException ( 
  Class.forName ( "COM.ibm.db2.jdbc.app.DB2Driver"). NewInstance (); 
  String url = "jdbc: db2: sample"; 
  Connection con = DriverManager.getConnection (url, "db2admin", "cherub"); 
  con.setAutoCommit (false); 

  Statement stmt = con.createStatement (); 
  ResultSet rs = stmt.executeQuery ( "select * from Employee"); 
  while (rs.next ()) ( 
  System.out.println (rs.getString (1) + "," + rs.getString (2)); 
  ) 
  ) 
  ) 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google
  • DZone
  • Netvouz
  • NewsVine
  • Technorati

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Tags: