If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > JDBC cant connect to DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-12-06, 20:51
MaoLi MaoLi is offline
Registered User
 
Join Date: Dec 2006
Posts: 3
Angry JDBC cant connect to DB2

hi all!
as the title....

OS:windows 2000 prefessional
DB2 version:8.2

----------codes----------------

package com.servinvent.itmanager.test;

import java.sql.*;


public class DB2Test {
static Connection con = null;
static Statement stmt = null;

static String url = "jdbc:db2AMPLE";
//String url = "jdbc:db2://172.16.104.47:50000/sample";
//String user = "root";
//String password = "root";
String user = "MAOLI";
String password = "111111";
DB2Test(){}


public static void main(String[] args) {

try{
//DriverManager.registerDriver(new COM.ibm.db2.jdbc.app.DB2Driver());
//Class.forName("org.gjt.mm.mysql.Driver").newInstan ce();
//Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").ne wInstance();
//Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").ne wInstance();
System.out.println("register start");
DriverManager.registerDriver(new COM.ibm.db2.jdbc.app.DB2Driver());
//Class.forName("com.ibm.db2.jcc.DB2Driver");
//Class.forName("com.ibm.db2.jdbc.net.DB2Driver");
System.out.println("----");
}catch(Exception e){
e.printStackTrace();
}
try {
con = DriverManager.getConnection(url);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from T$salary");
while (rs.next()){
System.out.println(rs.getString(1));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if (con != null)
con = null;
}

}
}

----------Exceptions-----------
java.sql.SQLException: java.lang.UnsatisfiedLinkError: no db2jdbc in java.library.path
at COM.ibm.db2.jdbc.app.DB2Driver.<init>(Unknown Source)
at com.servinvent.itmanager.test.DB2Test.main(DB2Test .java:27)
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager .java:532)
at java.sql.DriverManager.getConnection(DriverManager .java:193)
at com.servinvent.itmanager.test.DB2Test.main(DB2Test .java:35)

----------Environment--------
CLASSPATH:

.;D:\PROGRA~1\IBM\SQLLIB\java\db2java.zip;D:\PROGR A~1\IBM\SQLLIB\java\db2jcc.jar;D:\PROGRA~1\IBM\SQL LIB\java\sqlj.zip;D:\PROGRA~1\IBM\SQLLIB\java\db2j cc_license_cisuz.jar;D:\PROGRA~1\IBM\SQLLIB\java\d b2jcc_license_cu.jar;D:\PROGRA~1\IBM\SQLLIB\bin;D: \PROGRA~1\IBM\SQLLIB\java\common.jar

Path:

C:\ITManager\jdk-windows\bin;C:\ITManager\jdk-windows\jre\bin\client;C:\ITManager\bin;C:\WINNT\; C:\WINNT\system32;%SystemRoot%\system32;%SystemRoo t%;%SystemRoot%\System32\Wbem;D:\Program Files\Rational\ClearCase\bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;D:\PROGRA~1\IBM\SQLLIB\BIN;D: \PROGRA~1\IBM\SQLLIB\FUNCTION;D:\PROGRA~1\IBM\SQLL IB\SAMPLES\REPL

--------------------------------------------------------------------
Thanks!!!!
Reply With Quote
  #2 (permalink)  
Old 12-13-06, 09:51
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I am not sure what your problem is. It looks like you have tried a myriad of things. This is what works for me using the Type 4 driver:


Class.forName("com.ibm.db2.jcc.DB2Driver").newInst ance();
url = new String("jdbc:db2://" + server + ":" + port + "/" + serverDB);

java.sql.Connection c = java.sql.DriverManager.getConnection(url,username, passwd);


Andy
Reply With Quote
  #3 (permalink)  
Old 12-13-06, 22:40
MaoLi MaoLi is offline
Registered User
 
Join Date: Dec 2006
Posts: 3
thanks andy

i've killed the problem.
it must use IBM's JDK and the "db2jdbc.dll" should be at the root.library.path
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On