JDBC connection to DB2 Summary

Source: Internet
Author: User
Tags db2 client

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 .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.