当前位置: 技术问答>java相关
关于“ Connection reset by peer: socket write error”错误
来源: 互联网 发布时间:2015-08-23
本文导语: 我最近做了一个论坛程序,发现一个奇怪的现象:发帖子的时候,有时会出现一个帖子连发两遍的情况,即数据库里会有两条记录。 我发现一旦出现这种情况,服务器就会打印如下信息: 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());
}
}
|
看看是不是jsp线程并发的问题