如何从java8连接到db2数据库,我需要从java8连接到db2数据库,因为jdbc/odbc驱动程序已被弃用,我尝试使用ibm驱动程序,但仍然无法连接。在下面的集团中,我添加了我在执行时遇到的异常堆栈。
连接代码:
try
{
String url= "jdbc:db2://XXX1.xx.xxxop:1210/Database";
String user="userName";
Stirng password = "pwdd";
Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("**** Loaded the JDBC driver");
con = DriverManager.getConnection (url, user, password);
System.out.println("**** Created a JDBC connection to the data source");
stmt = con.createStatement();
System.out.println("**** Created JDBC Statement object");
rs = stmt.executeQuery("SELECT * form tablename");
System.out.println("**** Created JDBC ResultSet object");
while (rs.next()) {
val= rs.getString(1);
}
System.out.println("**** Fetched all rows from JDBC ResultSet");
rs.close();
System.out.println("**** Closed JDBC ResultSet");
stmt.close();
System.out.println("**** Closed JDBC Statement");
con.commit();
System.out.println ( "**** Transaction committed" );
con.close();
System.out.println("**** Disconnected from data source");
}
catch(Exception ex)
{
System.err.println("SQLException information");
}
StackTrace:
com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2030][11211][4.25.13]A commumication error occurred during operations on the connection's undelying socker, socket input stream, or socket output stream. Error location: Reply.fill() - insufficient data (-l). Message: Insufficient data, ERRORCODE=4499, SQLSTATE=08001
at com.ibm.db2.jcc.am.b6.a(b6.java:338)
at com.ibm.db2.jcc.t4.a.a(a.java:572)
at com.ibm.db2.jcc.t4.a.a(a.java:556)
at com.ibm.db2.jcc.t4.a.a(a.java:551)
at com.ibm.db2.jcc.t4.y.b(y.java:310)
at com.ibm.db2.jcc.t4.y.b(y.java:337)
at com.ibm.db2.jcc.t4.y.c(y.java:450)
at com.ibm.db2.jcc.t4.y.v(y.java:1219)
at com.ibm.db2.jcc.t4.z.a(z.java:53)
at com.ibm.db2.jcc.t4.b.c(b.java:1410)
at com.ibm.db2.jcc.t4.b.b(b.java:1282)
at com.ibm.db2.jcc.t4.b.b(b.java:833)
at com.ibm.db2.jcc.t4.b.a(b.java:804)
at com.ibm.db2.jcc.t4.b.a(b.java:441)
at com.ibm.db2.jcc.t4.b.a(b.java:414)
at com.ibm.db2.jcc.t4.b.<init>(b.java:352)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:233)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:200)
at com.ibm.db2.jcc.DV2Driver.connect(DB2Driver.java:471)
at com.ibm.db2.jcc.DV2Driver.connect(DB2Driver.java:113)
at java.sql.DriverManage.getConnection(DriverManager.java:664)
at java.sql.DriverManage.getConnection(DriverManager.java:247)
首先,在缓存中,删除System.err.println("SQLException information");
并添加ex.printStackTrace()
以了解确切的问题。