am new to db2
my java code is not establishing connection with db2.
when i exceute my code iam getting the following exception:
openConnection com.ibm.db2.jcc.b.SqlException: Failure in loading T2 native library db2jcct2
Pinned topic pls help db2 connection exception
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2012-02-22T16:40:19Z at 2012-02-22T16:40:19Z by jguillaumes
Re: pls help db2 connection exception2006-12-23T11:25:00ZThis is the accepted answer. This is the accepted answer.hi,
my connection code is like this
public Connection openConnection()
System.out.println("Exception in openConnection "+ e);
i have set classpath to
Sample Java program which connects DB2 database2011-10-07T08:36:46ZThis is the accepted answer. This is the accepted answer.
- SystemAdmin 110000D4XK
public class DB2Connect
+ public static void main(String argv)+
+ catch (ClassNotFoundException e)+
+ System.out.println("Please include Classpath Where your DB2 Driver is located");+
+ System.out.println("DB2 driver is loaded successfully");+
+ Connection conn = null;+
+ PreparedStatement pstmt = null;+
+ ResultSet rset=null;+
+ boolean found=false;+
+ String url = "jdbc:db2://localhost:50000/db2DbName"; // localhost (or) IP Address+
+ String userName = "db2_usr";+
+ String passWord = "db2_pwd";+
+ conn = DriverManager.getConnection(url, userName, passWord);+
+ if (conn != null)+
+ System.out.println("DB2 Database Connected");+
+ System.out.println("Db2 connection Failed ");+
+ pstmt=conn.prepareStatement("select sysdate from dual");+
+ System.out.println("System Date: "rset.getString(1));
+ if (found ==false)+
+ System.out.println("No Information Found");+
+ catch (SQLException e)+
+ System.out.println("DB2 Database connection Failed");+
Commands to execute program:
javac -classpath .;db2jcc4.jar;db2jcc_license_cu.jar DB2Connect.java
java -classpath .;db2jcc4.jar;db2jcc_license_cu.jar DB2Connect
Re: Sample Java program which connects DB2 database2012-02-22T15:15:40ZThis is the accepted answer. This is the accepted answer.
- SystemAdmin 110000D4XK
jguillaumes 11000093RP8 Posts
Re: pls help db2 connection exception2012-02-22T16:40:19ZThis is the accepted answer. This is the accepted answer.It seems like you are trying to use the type 2 (native) drivers, so the shared library db2jcct has to be in your DLL path (the way of specifying that depends on your operating system... for windows it has to be in the PATH, while for most unices it should be in the LD_LIBRARY_PATH).
You probably will want to use the type 4 driver (pure java) instead. To do so, be sure you specify the connection URL in this way:
For instance, for the SAMPLE database in a server running in your own machine using the default port (50000) it should be:
If you are using a connect uri of the style:
then you will be using the T2 driver and hence getting that exception.