For work relations, you can use DB2 and jdbcto connect to the db2java.zip package imported to the db2client.
DB2 supports type2 and type4 in JDBC connection 4. The difference between them is that you need to configure the DB2 client in type2 mode.
Your program will find the server correctly, and type4 will not be needed.
The method of type2 is very simple, as long as you have configured the DB2 client, it will be able to connect
Use com. IBM. db2.jdbc. App. db2driver as the driver
The type4 method is a bit different. Below is a simple test code.
Import java. SQL. connection;
Import java. SQL. sqlexception;
Import java. SQL. drivermanager; import java. SQL. databasemetadata;
Public class test {
Public static void main (string [] ARGs ){
Connection conn = NULL;
Try {
Class. forname ("com.ibm.db2.jdbc.net. db2driver ");
Try {
Conn = drivermanager. getconnection ("JDBC: DB2: // localhost: 6789/basdb", "username", "password ");
If (Conn! = NULL ){
Databasemetadata dbmd = conn. getmetadata ();
System. Out. println (dbmd. getdatabaseproductname ());
}
} Catch (sqlexception e ){
E. printstacktrace ();
}
} Catch (classnotfoundexception e ){
E. printstacktrace ();
}
}
}
Then run. If you can see the database name, it indicates that you have succeeded.
The port number 6789 is not the port number configured on the DB2 client.
Because net bridging is completed by one service listening to another port in DB2, this port is 6789 by default.
Of course, DBAs can also be modified.
1. Disable Web Services on the server;
2. Stop the JDBC listening process db2jd. db2jd generally starts port 6789,
Use PS-Ef | grep db2jd to view its process number.
Run the kill-9 <process no.> command to stop the service;
3. on the database server, go to the/usr/LPP/db2_07_01/java12 directory and run./usejdbc2 to enable jdbc2;
4. On the server, Su-<database instance username>
Run db2jstrt 6789 (this statement starts the db2jd process. 6789 is the default port on which the server listens to the jdbc2 connection and can be set to another non-conflicting port .)