weixin_42299147
2009-02-02 22:26
浏览 234
已采纳

小弟有一个问题很急啊

就是我有一个JSp空间 我获取数据库连接的时候会报错
我最初认为是我的数据库连接池写得有问题
但是我后来用jdbc来获取连接出现一样的问题
下面是异常代码
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** com.mysql.jdbc.CommunicationsException MESSAGE: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: Connection reset STACKTRACE: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:168) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1994) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2411) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723) at com.mysql.jdbc.Connection.execSQL(Connection.java:3250) at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5395) at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4118) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2762) at com.mysql.jdbc.Connection.(Connection.java:1553) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at com.mmx.db.DbConnection.getConnection(DbConnection.java:45) at com.mmx.RepeatCheck.doPost(RepeatCheck.java:45) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 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:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) ** END NESTED EXCEPTION ** Last packet sent to the server was 47 ms ago. STACKTRACE: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: Connection reset STACKTRACE: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:168) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1994) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2411) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723) at com.mysql.jdbc.Connection.execSQL(Connection.java:3250) at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5395) at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4118) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2762) at com.mysql.jdbc.Connection.(Connection.java:1553) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at com.mmx.db.DbConnection.getConnection(DbConnection.java:45) at com.mmx.RepeatCheck.doPost(RepeatCheck.java:45) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 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:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) ** END NESTED EXCEPTION ** Last packet sent to the server was 47 ms ago. at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2622) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723) at com.mysql.jdbc.Connection.execSQL(Connection.java:3250) at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5395) at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4118) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2762) at com.mysql.jdbc.Connection.(Connection.java:1553) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at com.mmx.db.DbConnection.getConnection(DbConnection.java:45) at com.mmx.RepeatCheck.doPost(RepeatCheck.java:45) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 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:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) ** END NESTED EXCEPTION ** Last packet sent to the server was 0 ms ago.
这个是程序代码
Connection con=null;
try
{Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://****/yyqnew2?useUnicode=true&characterEncoding=utf8","****","******");
}
catch(Exception e)
{
e.printStackTrace();

}
希望大家帮帮忙啊

[b]问题补充:[/b]
慢烦能说得详细些吗
我也感觉很奇怪啊
[b]问题补充:[/b]
我用c3p0尝试了的能建立连接池
但是有时候获取不到连接 有时候却能获取连接
感觉好像是mysql server不太稳定样
[b]问题补充:[/b]
你好 感谢你回答 主要是我所有分就只有这5分了 没有分了所以就只有给这5分了

我在本机用Php来连接数据库每次都成功
但是用Java来连接 偶尔能成功 经常报上面的错误
下面是php成功截图
[b]问题补充:[/b]
你好 你看图片没有啊
我就是直接用jdbc连接的啊
我还是用本机应用程序方式连接的
谢谢
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://*****/yyqnew2?useUnicode=true&characterEncoding=utf8","****","*****");
out.println(con);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select username from user_info limit 100");
while(rs.next())
{
out.println(rs.getString(1));

}
}
catch (Exception e)
{
out.println(e);
}
finally
{
try
{
rs.close();
stmt.close();
con.close();

}
catch(Exception e)
{
out.println(e);
}
}
[b]问题补充:[/b]
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure.

这个好像是说和MySQL的通信连接失败
[b]问题补充:[/b]
呵呵 那个是我补充问题的时候写错了 程序没有写错 呵呵

[b]问题补充:[/b]
我连接串什么地方写错了啊?
请明确说明啊 谢谢
[b]问题补充:[/b]
你好 我没有写端口啊

比如这样的
jdbc:mysql://www.google.com/databasename
这样的url有错误吗

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • wwwghost 2009-02-02 23:33
    已采纳

    不是程序问题,应该是MySQL Server出了毛病,或者是防火墙之类的东东在捣鬼!

    评论
    解决 无用
    打赏 举报
查看更多回答(5条)

相关推荐 更多相似问题