我是db2的新手。我想问一下是否可以仅通过我的Java应用程序连接到远程db2服务器上的db2数据库?仅使用类型为4的jdbc驱动程序即可吗?
我在构建路径中有db2jcc4驱动程序。
当我尝试这个简单的代码时
public static void main(String[] args) {
Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("Driver loaded");
try {
Connection dbConn = DriverManager.getConnection("jdbc:db2://192.168.0.103:50000/ABC", "****", "*****");
} catch (SQLException e) {
e.printStackTrace();
}
}
使用这个异常连接失败。我无法追踪具体发生了什么?
com.ibm.db2.jcc.am.SqlException: [jcc][t4][10262][11223][4.19.26] Unexpected Throwable caught: null. ERRORCODE=-4228, SQLSTATE=null
at com.ibm.db2.jcc.am.kd.a(Unknown Source)
at com.ibm.db2.jcc.am.kd.a(Unknown Source)
at com.ibm.db2.jcc.am.kd.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.b(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
at com.ibm.db2.jcc.t4.b.<init>(Unknown Source)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
at com.ibm.db2.jcc.DB2Driver.connect(Unknown Source)
at com.ibm.db2.jcc.DB2Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.connect.db2.ConnectToServer.main(ConnectToServer.java:22)
Caused by: java.lang.NullPointerException
at com.ibm.db2.jcc.am.Connection.completeSqlca(Unknown Source)
at com.ibm.db2.jcc.t4.z.q(Unknown Source)
at com.ibm.db2.jcc.t4.z.p(Unknown Source)
at com.ibm.db2.jcc.t4.z.l(Unknown Source)
at com.ibm.db2.jcc.t4.z.d(Unknown Source)
at com.ibm.db2.jcc.t4.b.k(Unknown Source)
at com.ibm.db2.jcc.t4.b.b(Unknown Source)
at com.ibm.db2.jcc.t4.b.a(Unknown Source)
... 12 more
此外,在执行getconnection操作后,db2diag.log 的内容为:
PID : 5110 TID : 140245920114432 PROC : db2sysc 0
INSTANCE: sachindb NODE : 000 DB : ABC
APPHDL : 0-46 APPID: 192.168.0.101.64054.151230182945
AUTHID : SACHINDB HOSTNAME: Sachin
EDUID : 22 EDUNAME: db2agent (ABC) 0
FUNCTION: DB2 UDB, base sys utilities, sqleIsDatabaseDirectoryConnectable, probe:6835
MESSAGE : ZRC=0x8005006D=-2147155859=SQLE_CA_BUILT
"SQLCA has been built and saved in component specific control block."
DATA #1 : SQLCA, PD_DB2_TYPE_SQLCA, 136 bytes
sqlcaid : SQLCA sqlcabc: 136 sqlcode: -1035 sqlerrml: 0
sqlerrmc:
sqlerrp : SQLE534
sqlerrd : (1) 0x00000000 (2) 0x00000000 (3) 0x00000000
(4) 0x00000000 (5) 0x00000000 (6) 0x00000000
sqlwarn : (1) (2) (3) (4) (5) (6)
(7) (8) (9) (10) (11)
sqlstate:
Class.forName()
。 - Andy Guibert