JDBC 连接抛出 SocketException
我有一个在 WAS 7.0 上运行的 Web 应用程序,该应用程序可以正常工作,并且可以连续运行几周,没有任何问题。当尝试针对 MS SQL 2005 执行PreparedStatement 时,它会突然开始抛出 SocketException。 首先,我们开始研究一些可能导致此问题的明显问题,例如未关闭连接、服务器重新启动、连接池大小等。但什么也没发生。我们在池中尝试了 WAS 的连接重试,但没有成功。与服务器重新启动没有一致的相关性。
我们运行的是 WAS 7,应用程序使用的是 JSF 1.2。这是受影响的代码,后面是堆栈跟踪。
try {
conn = DBManager.getInstance().getInpatientConnection();
String sql = "select * from Reviews where datediff(y,reviewedDate,getDate()) < 30";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
reviewed.add(rs.getString("authNum"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBManager.clean(conn, rs, ps);
}
痕迹...
0000002a SystemErr R Caused by: java.lang.ClassCastException: java.net.SocketException incompatible with java.sql.SQLException
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerPooledConnection.notifyEvent(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerConnection.notifyPooledConnection(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.DBComms.transmit(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.IOBuffer.sendCommand(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteQuery(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
0000002a SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecuteQuery(WSJdbcPreparedStatement.java:1099)
0000002a SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeQuery(WSJdbcPreparedStatement.java:720)
0000002a SystemErr R at com.bcbst.ipct.controllers.MemberListingController.initReviews(MemberListingController.java:266)
0000002a SystemErr R at com.bcbst.ipct.controllers.MemberListingController.<init>(MemberListingController.java:251)
0000002a SystemErr R at java.lang.J9VMInternals.newInstanceImpl(Native Method)
0000002a SystemErr R at java.lang.Class.newInstance(Class.java:1345)
0000002a SystemErr R at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:190)
0000002a SystemErr R ... 66 more
我不确定要提供什么其他信息。让我知道您认为我相关的任何其他信息。我用谷歌搜索了这么多,但没有发现任何有用的东西。
TIA
I have a web application that running on WAS 7.0 that works and will remain up for a couple weeks at a time with no issue. All of a sudden it will start throwing SocketExceptions when trying to execute a PreparedStatement against MS SQL 2005. At first we started looking at some of the obvious issues that might causing this like not closing a connection, server reboots, connection pool size, etc. But nothing is coming up. We tried WAS's connection retry in the pool and that didn't work. There is no consistent correlation with server reboots.
We're running WAS 7 and the app is using JSF 1.2. Here's the affected code followed by the stack trace.
try {
conn = DBManager.getInstance().getInpatientConnection();
String sql = "select * from Reviews where datediff(y,reviewedDate,getDate()) < 30";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
reviewed.add(rs.getString("authNum"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBManager.clean(conn, rs, ps);
}
The trace...
0000002a SystemErr R Caused by: java.lang.ClassCastException: java.net.SocketException incompatible with java.sql.SQLException
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerPooledConnection.notifyEvent(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerConnection.notifyPooledConnection(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.DBComms.transmit(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.IOBuffer.sendCommand(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteQuery(Unknown Source)
0000002a SystemErr R at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
0000002a SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.pmiExecuteQuery(WSJdbcPreparedStatement.java:1099)
0000002a SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeQuery(WSJdbcPreparedStatement.java:720)
0000002a SystemErr R at com.bcbst.ipct.controllers.MemberListingController.initReviews(MemberListingController.java:266)
0000002a SystemErr R at com.bcbst.ipct.controllers.MemberListingController.<init>(MemberListingController.java:251)
0000002a SystemErr R at java.lang.J9VMInternals.newInstanceImpl(Native Method)
0000002a SystemErr R at java.lang.Class.newInstance(Class.java:1345)
0000002a SystemErr R at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:190)
0000002a SystemErr R ... 66 more
I'm not sure what other info to provide. Let me know any other info you think my pertinent to know. I've Googled this tons and nothing useful has come up.
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的堆栈跟踪来看,它看起来像是 MSSQL JDBC 驱动程序中的错误。如果数据库脱机时抛出异常,您所能做的就是捕获 ClassCastException 作为解决方法。此外,这也可能是 Java 版本问题,因为 JDBC 驱动程序依赖于特定的“类层次结构”。
From your stack trace, it looks like a bug in MSSQL JDBC driver. All you can do is catching ClassCastException as a workaround, if the exception is thrown when your database is offline. Furthermore, it could be a Java version problem as well since the JDBC driver relies on a certain "class hierarchy".