DB2自己带jdbc驱动,具体位置在C:/Program Files/IBM/SQLLIB/java/db2jcc.jar
C:/Program Files/IBM/SQLLIB/java/db2jcc_license_cu.jar
C:/Program Files/IBM/SQLLIB/java/db2jcc_license_cisuz.jar
设置CLASSPATH=.;C:/ProgramFiles/IBM/SQLLIB/java/db2jcc.jar;
C:/ProgramFiles/IBM/SQLLIB/java/db2jcc_license_cu.jar;
C:/ProgramFiles/IBM/SQLLIB/java/db2jcc_license_cisuz.jar
注意:在使用jdbc连接db2时,一定要用ibm自己的jdk,
否则执行会出现错误,可能是ibm的jdbc驱动和sun的jdk不兼容的问题
具体位置在C:/Program Files/IBM/SQLLIB/java/jdk
例子:
import java.sql.*;
public class ConDB2{
Connection con;
Statement st;
ResultSet rs;
public ConDB2(){
try{
String name="com.ibm.db2.jcc.DB2Driver";
String url="jdbc:db2://localhost:50000/database";
Class.forName(name);
con=DriverManager.getConnection(url,"user","password");
System.out.println("连接成功!");
con.close();
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String args[]){
ConDB2 cd=new ConDB2();
}
}