今晚发现无法撰写日志,查看Resin日志如下,baidu和google搜索一系列解决方法皆未果。

奇怪的是,只是Statement无法操作数据库,select和update都正常。重启MySQL Server,错误仍旧,只有重启Resin才正常。真是郁闷。

错误有待研究。以下是错误日志:

STACKTRACE:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Software caused connection abort: socket write error

STACKTRACE:
java.net.SocketException: Software caused connection abort: socket write error
 at java.net.SocketOutputStream.socketWrite0(Native Method)
 at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
 at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
 at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
 at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
 at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2590)
 at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2523)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1517)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1626)
 at com.mysql.jdbc.Connection.execSQL(Connection.java:3031)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:943)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1184)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1101)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1086)
 at org.javawind.servlet.AjaxPost.ajax_SaveModify(AjaxPost.java:117)
 at org.javawind.servlet.AjaxPost.doPost(AjaxPost.java:47)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:153)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:91)
 at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
 at org.javawind.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:30)
 at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:76)
 at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
 at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:241)
 at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
 at com.caucho.server.port.TcpConnection.run(TcpConnection.java:586)
 at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:690)
 at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:612)
 at java.lang.Thread.run(Thread.java:595)
** END NESTED EXCEPTION **

Last packet sent to the server was 0 ms ago.
 at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2605)
 at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2523)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1517)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1626)
 at com.mysql.jdbc.Connection.execSQL(Connection.java:3031)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:943)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1184)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1101)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1086)
 at org.javawind.servlet.AjaxPost.ajax_SaveModify(AjaxPost.java:117)
 at org.javawind.servlet.AjaxPost.doPost(AjaxPost.java:47)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:153)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:91)
 at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
 at org.javawind.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:30)
 at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:76)
 at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
 at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:241)
 at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
 at com.caucho.server.port.TcpConnection.run(TcpConnection.java:586)
 at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:690)
 at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:612)
 at java.lang.Thread.run(Thread.java:595)
** END NESTED EXCEPTION **
对不起,操作数据库失败!-->Statement

问题已经得到解决:

doPost(...){
    try   {
      取连接;
      操作数据库;
    }finally   {
      释放连接;
    }
}

这个是最标准的做法,在init和destroy中获取和释放是不正确的做法