Servlet SQLException Communication link failure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bylum
    New Member
    • Mar 2007
    • 15

    #1

    Servlet SQLException Communication link failure

    Servlet SQLException Communication link failure java howto



    i can't connect jsp and database(mysql) .
    This is the exception:


    exception
    org.apache.jasp er.JasperExcept ion: javax.servlet.S ervletException : java.sql.SQLExc eption: Communication link failure: java.io.IOExcep tion, underlying cause: Unexpected end of input stream

    ** BEGIN NESTED EXCEPTION **

    java.io.IOExcep tion
    MESSAGE: Unexpected end of input stream

    STACKTRACE:

    java.io.IOExcep tion: Unexpected end of input stream
    at com.mysql.jdbc. MysqlIO.readPac ket(MysqlIO.jav a:109 6)
    at com.mysql.jdbc. MysqlIO.doHands hake(MysqlIO.ja va:62 6)
    at com.mysql.jdbc. Connection.crea teNewIO(Connect ion.j ava:1562)
    at com.mysql.jdbc. Connection.<ini t>(Connection.j ava:491)
    at com.mysql.jdbc. NonRegisteringD river.connect(N onReg isteringDriver. java:346)
    at java.sql.Driver Manager.getConn ection(Unknown Source)
    at java.sql.Driver Manager.getConn ection(Unknown Source)
    at org.apache.jsp. audio_jsp._jspS ervice(audio_js p.jav a:108)
    at org.apache.jasp er.runtime.Http JspBase.service (Http JspBase.java:98 )
    at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet .java:803)
    at org.apache.jasp er.servlet.JspS ervletWrapper.s ervic e(JspServletWra pper.java:390)
    at org.apache.jasp er.servlet.JspS ervlet.serviceJ spFil e(JspServlet.ja va:320)
    at org.apache.jasp er.servlet.JspS ervlet.service( JspSe rvlet.java:266)
    at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet .java:803)
    at org.apache.cata lina.core.Appli cationFilterCha in.in ternalDoFilter( ApplicationFilt erChain.java:29 0)
    at org.apache.cata lina.core.Appli cationFilterCha in.do Filter(Applicat ionFilterChain. java:206)
    at org.apache.cata lina.core.Stand ardWrapperValve .invo ke(StandardWrap perValve.java:2 28)
    at org.apache.cata lina.core.Stand ardContextValve .invo ke(StandardCont extValve.java:1 75)
    at org.apache.cata lina.core.Stand ardHostValve.in voke( StandardHostVal ve.java:128)
    at org.apache.cata lina.valves.Err orReportValve.i nvoke (ErrorReportVal ve.java:105)
    at org.apache.cata lina.core.Stand ardEngineValve. invok e(StandardEngin eValve.java:109 )
    at org.apache.cata lina.connector. CoyoteAdapter.s ervic e(CoyoteAdapter .java:212)
    at org.apache.coyo te.http11.Http1 1Processor.proc ess(H ttp11Processor. java:844)
    at org.apache.coyo te.http11.Http1 1Protocol$Http1 1Conn ectionHandler.p rocess(Http11Pr otocol.java:634 )
    at org.apache.tomc at.util.net.JIo Endpoint$Worker .run( JIoEndpoint.jav a:445)
    at java.lang.Threa d.run(Unknown Source)


    ** END NESTED EXCEPTION **


    org.apache.jasp er.servlet.JspS ervletWrapper.h andle JspException(Js pServletWrapper .java:565)
    org.apache.jasp er.servlet.JspS ervletWrapper.s ervic e(JspServletWra pper.java:414)
    org.apache.jasp er.servlet.JspS ervlet.serviceJ spFil e(JspServlet.ja va:320)
    org.apache.jasp er.servlet.JspS ervlet.service( JspSe rvlet.java:266)
    javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet .java:803)
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    What version of JDBC driver are you using?

    Comment

    • bylum
      New Member
      • Mar 2007
      • 15

      #3
      Originally posted by sicarie
      What version of JDBC driver are you using?
      i use mysql-connector-java-3.0.8-stable-bin.jar version of JDBC and
      com.mysql.jdbc. Driver

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by bylum
        i use mysql-connector-java-3.0.8-stable-bin.jar version of JDBC and
        com.mysql.jdbc. Driver
        Did you recently upgrade? Are you sure the driver is set correctly in the Classpath?

        I found this on MySQL's site.

        Comment

        • bylum
          New Member
          • Mar 2007
          • 15

          #5
          Originally posted by sicarie
          Did you recently upgrade? Are you sure the driver is set correctly in the Classpath?

          I found this on MySQL's site.
          i set the classpath =
          C:\Program Files\Java\jdk1 .6.0\jre\lib\ex t\mysql-connector-java-5.0.4-bin.jar;C:\Prog ram Files\Apache Software Foundation\Tomc at 6.0\lib\mysql-connector-java-3.0.8-stable-bin.jar;

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            Originally posted by bylum
            i set the classpath =
            C:\Program Files\Java\jdk1 .6.0\jre\lib\ex t\mysql-connector-java-5.0.4-bin.jar;C:\Prog ram Files\Apache Software Foundation\Tomc at 6.0\lib\mysql-connector-java-3.0.8-stable-bin.jar;
            Hmmm, I guess what process did you use to initiate the connection?

            (ie, used classforname to register the driver, created the con, created statement, etc...)

            Comment

            • bylum
              New Member
              • Mar 2007
              • 15

              #7
              Originally posted by sicarie
              Hmmm, I guess what process did you use to initiate the connection?

              (ie, used classforname to register the driver, created the con, created statement, etc...)

              this is my coding..

              <%
              String connectionURL = "jdbc:mysql ://localhost:3306/webaudio?user=r oot";
              Connection connection = null;
              Statement statement = null;
              ResultSet rs = null;
              %>
              <html>
              <head></head>
              <body>
              <table>
              <tr align="center"> <td align="center">
              <%
              Class.forName(" com.mysql.jdbc. Driver").newIns tance();
              connection = DriverManager.g etConnection(co nnectionURL, "root", "123");
              statement = connection.crea teStatement();
              rs = statement.execu teQuery("SELECT name FROM audio");

              out.println("<t able border=1>");
              out.println("<t r><td>Audio In Database</td></tr>");

              while (rs.next())
              {
              out.println("<t r><td>");
              String file = rs.getString("n ame");
              if((file!=null) )
              {
              out.println("<a href=rtsp://554@localhost/test/" + file + ">");
              out.println(fil e + "<br>");
              out.println("</a></td></tr>");
              }
              }
              out.println("</table>");

              rs.close();
              %>
              </td>></tr>
              </table>
              </body>
              <html>

              Comment

              • sicarie
                Recognized Expert Specialist
                • Nov 2006
                • 4677

                #8
                Using code tags helps the readability.

                So there are two things that I have seen:
                1) no try-catch. Lots of compilers will complain about this - but this also looks like javascript, which I know absolutely nothing about, so I could be wrong.

                2) on the code below, you use file!=null, and Java string comparisons should be done with String.equals() ; - in your case file.equals(nul l), and then a not around that.
                Code:
                String file = rs.getString("name");
                if((file!=null))
                {
                    out.println("<a href=rtsp://554@localhost/test/" + file + ">");
                    out.println(file + "<br>");
                    out.println("</a></td></tr>");
                }
                Try at least changing the second - I'm pretty sure that would throw an IOException.

                Comment

                Working...