我是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:
1条答案
按热度按时间7kqas0il1#
您是否在Java 7中使用AES加密机制?如果是,我通过Googull在IBM.com找到了此解决方案
否则,尝试直接创建DB2SimpleDataSource对象。
然后像这样连接
Connection c = db2.getConnection()
或Connection c = db2.getConnection("****", "*****")
另请参阅this similar question