This article describes four basic types of connection to DB2 in java. The following describes the four basic types of connection to DB2 in java, I hope you will be helpful in your future studies. The following articles will provide you with relevant knowledge. The following is a detailed description of the relevant content.
First: at present, IBM has not provided the JDBC driver for TYPE 1.
Type 2 driver: COM. ibm. DB2.jdbc. app. DB2Driver. The driver is also located in the package DB2java.zip. JDK must be able to access DB2's DB2jdbc. dll and so on.
Usage:
- Class.forName("COM.ibm.DB2.jdbc.app.DB2Driver").newInstance();
- String url = "jdbc:DB2:sample";
- Connection con = DriverManager.getConnection(url, user, password);
The TYPE 2 driver enables Java applications to call db2through JDBC. The call to DB2 JDBC type 2 driver is converted to a Java local method. java applications using this driver must run on a DB2 client, and JDBC requests are forwarded to the DB2 server through this client.
Before using the DB2 JDBC application driver to access the data source in the DB2 UDB for iSeries or DB2 for OS/390 or z/OS environment, you must install DB2 Connect Version 8. DB2 JDBC type 2 driver supports most of the JDBC and SQLJ functions described in the JDBC 1.2 specification, and supports some functions described in the JDBC 2.0 specification.
Type 3 Driver: COM.ibm.DB2.jdbc.net. DB2Driver, which is located in the package DB2java.zip.
Usage:
- Class.forName("COM.ibm.DB2.jdbc.net.DB2Driver").newInstance();
The target connection DB2 system listens to this service on the default port 6789 // you need to start the DB2jstrt command on the database server to enable the network port
- String url = "jdbc:DB2://host:6789:SAMPLE";
- Connection con = DriverManager.getConnection(url, user, password);
Type 4 Driver: com. ibm. DB2.jcc. DB2Driver, which is located in the package DB2jcc. jar.
In this case, the database encoding is UTF-8. Otherwise, an error is returned!
Usage:
- Class.forName("com.ibm.DB2.jcc.DB2Driver").newInstance();
- String url = "jdbc:DB2://host:50000/SAMPLE";
- Connection con = DriverManager.getConnection(url, user, password);
The above content is an introduction to the four types of java connection to DB2. I hope you will have some gains.