I need to connect DB2 with Java. Kindly help me to connect DB2 with java in ECLIPSE. It would be of great help if you could guide me step by s
Well, you first need to have the DB2 Driver in your classpath; namely the db2jcc4.jar file. A syntax mistake that I noticed is:-
You have the line as follows
conn = DriverManager.getConnection("jdbc:db2:sabarish","db2admin","Murugasaranam");
_______________________________________^^^_________________________________
You should add two forward slash characters(/) after db2: and before sabarish like this
conn = DriverManager.getConnection("jdbc:db2://sabarish","db2admin","Murugasaranam")
Driver name is depends on the driver we are using.
Use COM.ibm.db2.jdbc.app.DB2Drive
when db2java.zip
is in your path.
Use com.ibm.db2.jcc.DB2Driver
when db2jcc.jar
& db2jcc_license_cu.jar
are in your classpath.
Also follow the below tutorial
Razorsql Help
IBM JDBC help
These two drivers are loaded from different JARs. The latter is loaded from jt400.
for db2 old 8.x version you need to add this driver com.ibm.db2.jcc.DB2Driver
Neither of the examples above worked for me, but this did:
Class.forName("com.ibm.as400.access.AS400JDBCDriver");
You need to correct the package name.
Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
To add .jar in your project => Project + Properties + Java Build Path + Select "Libraries" tab + Add External Jars...