-2

How to connect to db2 database from java8, I need to connect to db2 database from java8 as jdbc/odbc drivers has been deprecated, I tried using the ibm driver but still not able to connect. In the below bloc ive added the exception stack which I face while executing.

Connection Code:

            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)
mao
  • 11,321
  • 2
  • 13
  • 29
dean
  • 79
  • 1
  • 2
  • 9
  • 2
    Add details like where you got your JDBC driver from, the code you are using and the error message. – data_henrik May 18 '20 at 09:00
  • It is rarely useful to only print `"SQLException information"` when an error occurs. Please provide a [mre] with actual exception stacktraces. – Mark Rotteveel May 18 '20 at 11:35
  • com.ibm.db2.jcc.am.disconnectnontransientconnectionexception errorcode=-4499 sqlstate=08001 , this is the exception which I get when i execute the code. – dean May 18 '20 at 13:32
  • sqlstate 08001 means "The connection was unable to be established to the application server or other server." The sqlcode -4499 means "A fatal error occurred that resulted in a disconnect from the data source. The existing connection has become unusable ". Edit your code to Call SQLException.getMessage to retrieve specific information about the problem. You can also find examples of doing this. – mao May 18 '20 at 15:02
  • 1
    Please [edit] your question and add the full exception stacktrace. – Mark Rotteveel May 18 '20 at 15:58
  • 1
    Edit your question to show the URL in plain text, including any connection attributes (disguise anything confidential). The symptom can happen with misconfigured security/encryption or non-default authentication settings etc. There may also be additional details in the Db2-server diagnostics (you can ask the DBA about that). Also you should tell us in the question which *platform* of Db2-server you use (Db2-for-Z/OS, Db2-for-i-series(as/400), Db2 for Linux/Unix/Windows. – mao May 19 '20 at 18:26
  • DB2 Server is DB2 for Z/OS . – dean May 20 '20 at 06:26
  • 1
    Find another java application that connects from your workstation to same database. Compare URL and connection attributes. Your test app must do the same. Otherwise, talk with your Z/OS DBA team, ask to confirm port number, ask how authentication and encryption-in-transit is done for this subsystem (it may be certificate authentication, it may be TLS, or trusted contexts etc ). This is all site specific so you must talk with local Db2-for-Z/OS folks. – mao May 20 '20 at 07:58

1 Answers1

-1

First, in cache, remove System.err.println("SQLException information"); and add ex.printStackTrace() so as to know the exact issue.

Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
VIKRAM
  • 52
  • 7