当前位置: 技术问答>java相关
关 于 “ Connection reset by peer: socket write error”错误
来源: 互联网 发布时间:2015-08-22
本文导语: 我最近做了一个论坛程序,发现一个奇怪的现象:发帖子的时候,有时会出现一个帖子连发两遍的情况,即数据库里会有两条记录。 我发现一旦出现这种情况,服务器就会打印如下信息: 2002-08-28 01:31:48 - Ctx( /new...
我最近做了一个论坛程序,发现一个奇怪的现象:发帖子的时候,有时会出现一个帖子连发两遍的情况,即数据库里会有两条记录。
我发现一旦出现这种情况,服务器就会打印如下信息:
2002-08-28 01:31:48 - Ctx( /newbbs ): IOException in: R( /newbbs + /post_ok.jsp + null) Connection reset by peer: socket write error
2002-08-28 01:31:48 - Ctx( /newbbs ): IOException in: R( /newbbs + /post_ok.jsp + null) Connection reset by peer: socket write error
请问为什么?
我的开发环境:tomcat 3.2 /mysql/服务器在WIN2000上,数据库在LINUX上
===========================
JSP页面插入语句:
//插入froum表,记录发帖
DBconnBean.openConnection();
……
String SQL1 = "insert into forum(board,boardname,bq,UID,name,title,detail,sign,artsize,msg_inform,time,lasttime,ip,vtime,new,nickname) values ('"+ board +"','"+ boardsname +"','"+ bq +"','"+ ID +"','"+ name +"','"+ title +"','"+ detail +"','"+ sign_detail +"','"+ artsize +"','"+ msg_inform +"',now(),now(),'"+ request.getRemoteAddr() +"','"+ vtime +"','1','"+ nick +"')";
DBconnBean.executeQuery(SQL1);
……
===============================
DbConnection.java代码
import java.util.*;
import java.sql.*;
import java.io.*;
public class DbConnection{
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
public DbConnection(){
}
/************************************************
* openConnection
* read file "db.properties"
************************************************/
public boolean openConnection(){
Properties prop = new Properties();
try{
InputStream is = getClass().getResourceAsStream("db.properties");
prop.load(is);
if(is != null) is.close();
}catch(IOException e){
System.out.println("[DbConnection] Open db.properties File, Error!");
}
String jdbc = prop.getProperty("driver");
String uri = prop.getProperty("url");
//System.out.println("jdbc=[" + jdbc + "]");
//System.out.println("uri=[" + uri + "]");
try{
Class.forName(jdbc).newInstance();
}catch(ClassNotFoundException e){
System.out.println("JDBC login, Error!@" + e.getMessage());
return false;
}catch (Exception e){
System.err.println("Unable to load driver!");
e.printStackTrace();
}
try{
this.conn = DriverManager.getConnection (uri);
}catch(SQLException e){
System.out.println("Generate Connection, Error!" + e.getMessage());
return false;
}
return true;
}
/*************************************************
* executeQuery and executeUpdate
* query and update DB
*************************************************/
public ResultSet executeQuery(String query) throws SQLException{
stmt = conn.createStatement();
rset = stmt.executeQuery(query);
return rset;
}
public void executeUpdate(String query) throws SQLException{
stmt = conn.createStatement();
stmt.executeUpdate(query);
if(stmt != null) stmt.close();
}
public void intodb(String query,String title) throws SQLException{
stmt = conn.createStatement();
System.out.println("=================="+title+"==================");
stmt.executeUpdate(query);
System.out.println("******************"+title+"******************");
if(stmt != null) stmt.close();
}
public void close() throws SQLException{
if(conn != null) conn.close();
if(rset != null) rset.close();
if(stmt != null) stmt.close();
}
protected void finalize() throws Throwable{
close();
}
public static void main(String[] args){
//Design for test purpose.
DbConnection dc = new DbConnection();
System.out.println(dc.openConnection());
}
}
我发现一旦出现这种情况,服务器就会打印如下信息:
2002-08-28 01:31:48 - Ctx( /newbbs ): IOException in: R( /newbbs + /post_ok.jsp + null) Connection reset by peer: socket write error
2002-08-28 01:31:48 - Ctx( /newbbs ): IOException in: R( /newbbs + /post_ok.jsp + null) Connection reset by peer: socket write error
请问为什么?
我的开发环境:tomcat 3.2 /mysql/服务器在WIN2000上,数据库在LINUX上
===========================
JSP页面插入语句:
//插入froum表,记录发帖
DBconnBean.openConnection();
……
String SQL1 = "insert into forum(board,boardname,bq,UID,name,title,detail,sign,artsize,msg_inform,time,lasttime,ip,vtime,new,nickname) values ('"+ board +"','"+ boardsname +"','"+ bq +"','"+ ID +"','"+ name +"','"+ title +"','"+ detail +"','"+ sign_detail +"','"+ artsize +"','"+ msg_inform +"',now(),now(),'"+ request.getRemoteAddr() +"','"+ vtime +"','1','"+ nick +"')";
DBconnBean.executeQuery(SQL1);
……
===============================
DbConnection.java代码
import java.util.*;
import java.sql.*;
import java.io.*;
public class DbConnection{
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
public DbConnection(){
}
/************************************************
* openConnection
* read file "db.properties"
************************************************/
public boolean openConnection(){
Properties prop = new Properties();
try{
InputStream is = getClass().getResourceAsStream("db.properties");
prop.load(is);
if(is != null) is.close();
}catch(IOException e){
System.out.println("[DbConnection] Open db.properties File, Error!");
}
String jdbc = prop.getProperty("driver");
String uri = prop.getProperty("url");
//System.out.println("jdbc=[" + jdbc + "]");
//System.out.println("uri=[" + uri + "]");
try{
Class.forName(jdbc).newInstance();
}catch(ClassNotFoundException e){
System.out.println("JDBC login, Error!@" + e.getMessage());
return false;
}catch (Exception e){
System.err.println("Unable to load driver!");
e.printStackTrace();
}
try{
this.conn = DriverManager.getConnection (uri);
}catch(SQLException e){
System.out.println("Generate Connection, Error!" + e.getMessage());
return false;
}
return true;
}
/*************************************************
* executeQuery and executeUpdate
* query and update DB
*************************************************/
public ResultSet executeQuery(String query) throws SQLException{
stmt = conn.createStatement();
rset = stmt.executeQuery(query);
return rset;
}
public void executeUpdate(String query) throws SQLException{
stmt = conn.createStatement();
stmt.executeUpdate(query);
if(stmt != null) stmt.close();
}
public void intodb(String query,String title) throws SQLException{
stmt = conn.createStatement();
System.out.println("=================="+title+"==================");
stmt.executeUpdate(query);
System.out.println("******************"+title+"******************");
if(stmt != null) stmt.close();
}
public void close() throws SQLException{
if(conn != null) conn.close();
if(rset != null) rset.close();
if(stmt != null) stmt.close();
}
protected void finalize() throws Throwable{
close();
}
public static void main(String[] args){
//Design for test purpose.
DbConnection dc = new DbConnection();
System.out.println(dc.openConnection());
}
}
|
当用户点击发送按钮之后disable这个按钮。
|
WSAECONNRESET (10054) Connection reset by peer.
存在的连接被远程主机强制关闭。通常原因为:远程主机上对等方应用程序突然停止运行,或远程主机重新启动,或远程主机在远程方套接字上使用了“强制”关闭(参见setsockopt(SO_LINGER))。另外,在一个或多个操作正在进行时,如果连接因“keep-alive”活动检测到一个失败而中断,也可能导致此错误。此时,正在进行的操作以错误码WSAENETRESET失败返回,后续操作将失败返回错误码WSAECONNRESET。
存在的连接被远程主机强制关闭。通常原因为:远程主机上对等方应用程序突然停止运行,或远程主机重新启动,或远程主机在远程方套接字上使用了“强制”关闭(参见setsockopt(SO_LINGER))。另外,在一个或多个操作正在进行时,如果连接因“keep-alive”活动检测到一个失败而中断,也可能导致此错误。此时,正在进行的操作以错误码WSAENETRESET失败返回,后续操作将失败返回错误码WSAECONNRESET。