Page 1 of 1

JDBC DB2 Connection does not respond

PostPosted: Thu Apr 04, 2013 10:42 am
by RameshK
Hi,

I am trying to connect IBM Mainframe DB2 8.1 database using Eclipse
application class through JDBC db2 type 4 universal driver. this is the
following code of the DB2Connection.java

import java.sql.Connection;
import java.sql.SQLException;

public class DB2Connection {

public static void main(String[] argv) {

Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rset=null;
boolean found=false;

try {

Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("DB2 driver is loaded successfully");
conn = DriverManager.getConnection("jdbc:db2://220.227.139.118:23
/TWSDB","tws0001","mar2013");
if (conn != null)
{
System.out.println("DB2 Database Connected");
}else{
System.out.println("Db2 connection Failed ");
}
} catch (Exception e) {
System.out.println("DB2 Database connection Failed");
e.printStackTrace();
}finally{
try {
if(conn!=null){
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

DB2 driver is loaded successfully

after the above message

I got the following exception

DB2 Database connection Failed
com.ibm.db2.jcc.am.yn: [jcc][t4][2030][11211][3.57.82] A communication error occurred during operations on the connection's underlying socket, socket input stream,
or socket output stream. Error location: Reply.fill(). Message: Read timed out. ERRORCODE=-4499, SQLSTATE=08001
at com.ibm.db2.jcc.am.bd.a(bd.java:319)
at com.ibm.db2.jcc.t4.a.a(a.java:365)
at com.ibm.db2.jcc.t4.a.a(a.java:360)
at com.ibm.db2.jcc.t4.ab.b(ab.java:202)
at com.ibm.db2.jcc.t4.ab.c(ab.java:243)
at com.ibm.db2.jcc.t4.ab.c(ab.java:354)
at com.ibm.db2.jcc.t4.ab.v(ab.java:1139)
at com.ibm.db2.jcc.t4.bb.a(bb.java:42)
at com.ibm.db2.jcc.t4.b.m(b.java:1240)
at com.ibm.db2.jcc.t4.b.b(b.java:1114)
at com.ibm.db2.jcc.t4.b.c(b.java:701)
at com.ibm.db2.jcc.t4.b.b(b.java:687)
at com.ibm.db2.jcc.t4.b.a(b.java:374)
at com.ibm.db2.jcc.t4.b.<init>(b.java:310)
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection( DB2SimpleDataSource.java:214)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:2 24)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.ford.gaps.dao.DB2Connection.main(DB2Connection .java:34)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at com.ibm.db2.jcc.t4.ab.b(ab.java:195)
... 15 more

I closed the connection properly in the finally block,so some other thing
that would not allow to connect DB2 on mainframe.

I added the db2 jdbc jars on the classpath

1) db2jcc.jar

2) db2jcc_license_cisuz.jar

3) db2jcc_license_cu.jar

Can anybody share your points here?

Thanks and regards,
Ramesh K

Re: JDBC DB2 Connection does not respond

PostPosted: Thu Apr 04, 2013 2:40 pm
by Robert Sample
I don't know JDBC but I do know you are attempting to connect on port 23, which is the default telnet port. The default JDBC port from what I can see is 1527, but I suspect that might vary depending upon which instance of DB2 you want to connect to. Your time out is probably because your program is not sending back telnet responses to the telnet port.

And did you change the IP address before posting so you did not expose your site's mainframe to the entire world?

Re: JDBC DB2 Connection does not respond

PostPosted: Thu Apr 04, 2013 5:42 pm
by NicC
Multiple posting - locked.