Reputation: 89
This is my Class trying to connect Db2:
package Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Db2Connection {
public static void main(String[] args) {
Connection conn = null;
String driverName = "COM.ibm.db2.jdbc.app.DB2Driver";
String db2ConnectString = "jdbc:db2:DB2XAT33;UID=G37RSF4;PWD=HOT22RST";
try {
Class.forName(driverName);
conn = DriverManager.getConnection(db2ConnectString);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("ClassNotFoundException Message -- "+ e.getMessage());
e.printStackTrace();
}catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("SQLException Message -- " + e.getMessage());
e.printStackTrace();
}catch (UnsatisfiedLinkError e) {
// TODO Auto-generated catch block
System.out.println("UnsatisfiedLinkError Message -- " + e.getMessage());
e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("General Exception Message -- " + e.getMessage());
e.printStackTrace();
}
}
}
when i run this i am getting below Exception:
java.lang.UnsatisfiedLinkError: SQLAllocEnv
at COM.ibm.db2.jdbc.app.DB2Driver.<init>(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2Driver.<clinit>(Unknown Source)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java:142)
I have Db2.zip in Folder "C:\Program Files\IBM\SQLLIB\java\". And i added Db2.zip and ojdbc.jar to my Package via JavaBuildpath.
Upvotes: 1
Views: 940
Reputation: 18945
You are trying to use the type 2 (the so called "app") driver, which 1) requires that you install at least the runtime client with native CLI/ODBC libraries and 2) is deprecated.
Consider using the type 4 ("jcc") driver, which is pure Java. More information can be found here: implement type 4 jdbc driver in DB2
Upvotes: 1
Reputation: 1072
Check the LD_LIBRARY_PATH shell environment variable; it needs to contain the directory where db2's libraries are. Google for "websphere db2 ld_library_path" without the quotes.
Upvotes: 1