Today, we find a service program on the server has a problem, the software throws: Connection reset by Peer:socket write error
Unable to provide service, looked for a reason, originally because the database server restarts, connection pool database connection connection cannot create a new statement, resulting in the inability to provide normal service.
To Baidu Search, see an article and I encountered a similar problem, the solution although it seems not very good approach, but also practical:
WORKAROUND: Create a statement before use, and if an exception is thrown, the connection is disconnected and reconnected.
if(conn = =NULL||conn.isclosed ()) {Conn=addconnetion ()}Else{Statement St=NULL; ResultSet RS=NULL; Try{St= Conn.createstatement ();//This is not a definite step .Rs=st.executequery ("Select 0");//This is the step to determine } Catch(SQLException e) {conn=addconnetion (); } finally { Try { if(rs!=NULL) {rs.close (); RS=NULL; } if(St! =NULL) {st.close (); St=NULL; } } Catch(SQLException e) {e.printstacktrace (); } }}
2008-11-26
JAVA: Connection pooling does not automatically identify a workaround after a database restart