3 Replies Latest reply on Sep 17, 2009 8:33 AM by 843859

    Can't connect to database

    843859

      I'm using db2jcc4.jar to try and connect to a database. When it attempts to connect it hangs and then gives this error:

      Sep 14, 2009 3:46:39 PM org.apache.catalina.core.ApplicationContext log SEVERE: Could not create BeerDB object: [jcc][t4][2030][11211][3.50.152] A communication error occurred during operations on the connection's underlying socket, socket input stream, or socket output stream.  Error location: Reply.fill().  Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001 com.ibm.db2.jcc.b.gm: [jcc][t4][2030][11211][3.50.152] A communication error occurred during operations on the connection's underlying socket, socket input stream, or socket output stream.  Error location: Reply.fill().  Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001 at com.ibm.db2.jcc.b.wc.a(wc.java:283) at com.ibm.db2.jcc.t4.a.a(a.java:352) at com.ibm.db2.jcc.t4.ab.b(ab.java:219) at com.ibm.db2.jcc.t4.ab.c(ab.java:237) at com.ibm.db2.jcc.t4.ab.c(ab.java:348) at com.ibm.db2.jcc.t4.ab.v(ab.java:1133) at com.ibm.db2.jcc.t4.bb.a(bb.java:41) at com.ibm.db2.jcc.t4.b.i(b.java:1357) at com.ibm.db2.jcc.t4.b.b(b.java:1249) at com.ibm.db2.jcc.t4.b.s(b.java:1020) at com.ibm.db2.jcc.t4.b.c(b.java:632) at com.ibm.db2.jcc.t4.b.b(b.java:618) at com.ibm.db2.jcc.t4.b.a(b.java:360) at com.ibm.db2.jcc.t4.b.<init>(b.java:298) at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:193) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at my.db.BeerDB.connect(BeerDB.java:80) at my.db.BeerDB.<init>(BeerDB.java:57) at my.listener.SessionListener.sessionCreated(SessionListener.java:16) at org.apache.catalina.session.StandardSession.tellNew(StandardSession.java:397) at org.apache.catalina.session.StandardSession.setId(StandardSession.java:369) at org.apache.catalina.session.ManagerBase.createSession(ManagerBase.java:827) at org.apache.catalina.session.StandardManager.createSession(StandardManager.java:291) at org.apache.catalina.connector.Request.doGetSession(Request.java:2324) at org.apache.catalina.connector.Request.getSession(Request.java:2074) at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833) at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:844) at org.apache.jasper.runtime.PageContextImpl._initialize(PageContextImpl.java:146) at org.apache.jasper.runtime.PageContextImpl.initialize(PageContextImpl.java:124) at org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryImpl.java:107) at org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:63) at org.apache.jsp.all_002ddrinkers_jsp._jspService(all_002ddrinkers_jsp.java:46) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Unknown Source) Sep 14, 2009 3:46:39 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet jsp threw exception java.lang.InstantiationException: bean db not found within scope at org.apache.jsp.all_002ddrinkers_jsp._jspService(all_002ddrinkers_jsp.java:71) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Unknown Source)

      BeerDB is the name of my class, here's the relevant code from that class:

      package my.db; import java.sql.*; import javax.naming.*; import javax.sql.DataSource; import java.util.EnumMap; import java.util.ArrayList; import java.util.Properties; import com.ibm.db2.jcc.DB2Driver; public class BeerDB {     static     {         try         {             Class.forName("com.ibm.db2.jcc.DB2Driver");         }         catch (ClassNotFoundException e)         {             // TODO Auto-generated catch block             e.printStackTrace();         }     }         protected Connection _conn = null;     public BeerDB() throws NamingException, SQLException     {         connect();     }     public void connect() throws NamingException, SQLException     {         System.out.println("ATTEMPTING TO CONNECT");         // Is this a reconnection?  If so, disconnect first.         if (_conn != null)             disconnect();         try         {                                 //Remote connection             String url = "jdbc:db2://cps116.cod.cs.duke.edu:60301/dbcourse";             url += ":retrieveMessagesFromServerOnGetMessage=true;";             String userid = myID;             String passwd = myPassword;             _conn = DriverManager.getConnection(url, userid, passwd);                     catch (SQLException e)         {             if (_conn != null)                 disconnect();             throw e;         }     } }
        • 1. Re: Can't connect to database
          843859
          JFactor2004 wrote:
          ERRORCODE=-4499, SQLSTATE=08001
          Google learns me that the URL is plain wrong (i.e. hostname or port) or that the DB is simply not reachable by network (i.e. some hardware or software is blocking the connection like a firewall or router).
          protected Connection _conn = null;
          Storing an expensive/external resource like connection as a class/instance variable is a very bad practice. Keep it threadlocal (inside the method block) to avoid resource leaks and unnecessary resource sharing. Follow the general JDBC coding practices: acquire and close the connection, statement and resultset in the shortest possible scope.
          • 2. Re: Can't connect to database
            843859
            Hmm...well I'm doing what the example code I was given says to do so I guess I'll have to do some more looking as it seems to not be a java problem then.
            • 3. Re: Can't connect to database
              843859
              Hi

              Did you come right with this