By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,277 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,277 IT Pros & Developers. It's quick & easy.

Servlet SQLException Communication link failure

P: 15
Servlet SQLException Communication link failure java howto



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


exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream

** BEGIN NESTED EXCEPTION **

java.io.IOException
MESSAGE: Unexpected end of input stream

STACKTRACE:

java.io.IOException: Unexpected end of input stream
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:109 6)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:62 6)
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1562)
at com.mysql.jdbc.Connection.<init>(Connection.java:4 91)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:346)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.apache.jsp.audio_jsp._jspService(audio_jsp.jav a:108)
at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:390)
at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:212)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:445)
at java.lang.Thread.run(Unknown Source)


** END NESTED EXCEPTION **


org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:565)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:414)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
Mar 23 '07 #1
Share this Question
Share on Google+
7 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
What version of JDBC driver are you using?
Mar 23 '07 #2

P: 15
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
Mar 24 '07 #3

sicarie
Expert Mod 2.5K+
P: 4,677
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.
Mar 24 '07 #4

P: 15
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\ext\mysql-connector-java-5.0.4-bin.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\mysql-connector-java-3.0.8-stable-bin.jar;
Mar 24 '07 #5

sicarie
Expert Mod 2.5K+
P: 4,677
i set the classpath =
C:\Program Files\Java\jdk1.6.0\jre\lib\ext\mysql-connector-java-5.0.4-bin.jar;C:\Program Files\Apache Software Foundation\Tomcat 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...)
Mar 24 '07 #6

P: 15
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=root";
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").newInstance ();
connection = DriverManager.getConnection(connectionURL, "root", "123");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT name FROM audio");

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

while (rs.next())
{
out.println("<tr><td>");
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>");
}
}
out.println("</table>");

rs.close();
%>
</td>></tr>
</table>
</body>
<html>
Mar 24 '07 #7

sicarie
Expert Mod 2.5K+
P: 4,677
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(null), and then a not around that.
Expand|Select|Wrap|Line Numbers
  1. String file = rs.getString("name");
  2. if((file!=null))
  3. {
  4.     out.println("<a href=rtsp://554@localhost/test/" + file + ">");
  5.     out.println(file + "<br>");
  6.     out.println("</a></td></tr>");
  7. }
  8.  
Try at least changing the second - I'm pretty sure that would throw an IOException.
Mar 24 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.