ITPub博客

首页 > 数据库 > 数据库开发技术 > JDBC differences between the DB2 Universal JDBC Driver and other DB2 JDBC drivers

JDBC differences between the DB2 Universal JDBC Driver and other DB2 JDBC drivers

原创 数据库开发技术 作者:zenzuguo 时间:2005-11-02 12:40:19 0 删除 编辑

JDBC differences between the DB2 Universal JDBC Driver and other DB2 JDBC drivers

1:DB2 Universal JDBC Driver:

url="jdbc:db2://host:50000/DataBase";
driver:com.ibm.db2.jcc.DB2Driver
jars:db2jcc.jar
DataBase Encoding:utf-8

Installs the db2jcc.jar and sqlj.zip files and adds them to the system 4 CLASSPATH 4
Installs file db2jcct2.dll, which is required for Universal Type 2 Connectivity, in the sqllibbin 4 directory


Exception1: encoding not supported:
com.ibm.db2.jcc.b.DisconnectException: encoding not supported!!

解决办法:在db2里建库时要选择utf-8编码(在建库的第六步)

网上讨论:
(1) db2的驱动要使用(db2jcc.jar),否则(用db2java.zip)在websphere下很难正确连接到db2,虽然在tomcat下能正常连接;
在db2里建库时要选择utf-8编码(在建库的第六步),否则连接时报"com.ibm.db2.jcc.b.DisconnectException: encoding not supported!!"异常;

(2) 是IBM JDK. 把Squirrel SQL运行的Java_home设置为WSAD的jre_home

CODE:

使用db2jcc.jar连接,code如下:(endb使用的encoding是utf-8)
String url="jdbc:db2://zengal:50000/endb";
String user="db2admin";
String password="zenzuguo";
try {
// Load the DB2(R) Universal JDBC Driver with DriverManager
Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection conn=DriverManager.getConnection(url,user,password);

System.out.println("Connection Successful");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch(SQLException esx){
esx.printStackTrace();
}


2: DB2 JDBC Type 2 Driver (deprecated)

url="jdbc:db2:host:DataBase";
driver:COM.ibm.db2.jdbc.net.DB2Driver
jars:db2jcc.jar,db2java.zip
DataBase Encoding:utf-8/GBK

(或者如果是本地程序连本地db2url可以这样写:
url="jdbc:db2:DataBase"
driver:COM.ibm.db2.jdbc.app.DB2Driver)

Installs the db2java.zip file and adds it to the system CLASSPATH
注意: (同时还要将db2jcc.jar加入classpath否则在构造conection pool(如avalon)时,出错)
但是普通情况下连接正常


使用db2java.zip连接,code如下:(endb使用的encoding是utf-8)
String url="jdbc:db2:zengal:endb";
String user="db2admin";
String password="zenzuguo";
try {
// Load the DB2(R) Universal JDBC Driver with DriverManager
Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection conn=DriverManager.getConnection(url,user,password);

System.out.println("Connection Successful");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch(SQLException esx){
esx.printStackTrace();
}

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/106285/viewspace-809154/,如需转载,请注明出处,否则将追究法律责任。

下一篇: java webstart
请登录后发表评论 登录
全部评论

注册时间:2012-12-30

  • 博文量
    84
  • 访问量
    828862