Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MySQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求助:JSP远程访问数据库错误:java.net.SocketException: Connection reset
zgia





发贴: 6
积分: 0
于 2006-11-06 12:33 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
一台合肥的机器机器A(电信),访问北京铁通的mysql服务器。直接用mysql客户端可以连接上,而且ping的值平均才30ms。当使用jsp的JDBC连接,却出现这样的错误:
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)
......
......
数据连接出错,请确保用户名,密码和服务器名没有错误

JSP文件的内容是:

<%@ page import="java.sql.*,java.util.*" %><%@ page contentType="text/html;charset=UTF-8"%><%
  java.sql.Connection sqlConn;
  java.sql.Statement sqlStmt;
  java.sql.ResultSet sqlRst;
  try{
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    sqlConn=java.sql.DriverManager.getConnection("jdbc:mysql://ip:3306/mintel?useUnicode=true&characterEncoding=UTF-8", "readonly","readonly");
    sqlStmt=sqlConn.createStatement();

    out.println("<p align=center>数据库连接正常.");
    try{
      String query="select userId from nd_users";
      ResultSet rs =sqlStmt.executeQuery(query);
      int i=0;
      while(rs.next()){
        i++;
      }
      out.println("<br align=center>"+"查询到的数据条目:"+i);
      rs.close();

    }catch(Exception ex){
      out.println("<p align=center>"+ex.toString());
      out.println("<p align=center><font color=red>数据查询出错</font>");
    }
    sqlStmt.close();
    sqlConn.close();

  }catch(Exception e){
    out.println("<p align=center>"+e.toString());
    out.println("<p align=center><font color=red>数据连接出错,请确保用户名,密码和服务器名没有错误</font>");
  }
    
  out.println("<br><br>");

%>

我连接了几十次,只有几次连接成功。而前几天连接一直都正常。
请问造成这个错误的原因是啥,如何解决?


zgia edited on 2006-11-06 12:36

开始学JAVA
作者 Re:求助:JSP远程访问数据库错误:java.net.SocketException: Connection reset [Re:zgia]
zcjl

涅槃



发贴: 537
积分: 65
于 2006-11-06 13:33 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如果相同的代码,十几次有几次能连接成功,多半就是网络问题了
你可以单独写个Java代码测试一下jdbc去连远程数据库的结果



作者 Re:求助:JSP远程访问数据库错误:java.net.SocketException: Connection reset [Re:zgia]
zgia





发贴: 6
积分: 0
于 2006-11-06 15:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
jsp也是编译为servlet的啊


开始学JAVA
作者 Re:求助:JSP远程访问数据库错误:java.net.SocketException: Connection reset [Re:zgia]
zcjl

涅槃



发贴: 537
积分: 65
于 2006-11-06 15:44 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的意思是,你写一个不依赖于容器的UnitTest类去测试


作者 Re:求助:JSP远程访问数据库错误:java.net.SocketException: Connection reset [Re:zgia]
zgia





发贴: 6
积分: 0
于 2006-11-06 17:23 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
同样的错误啦。郁闷啊。


开始学JAVA

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2018 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923