dharga
dharga

Reputation: 2217

JDBC Connection throwing SocketException

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

Upvotes: 3

Views: 1113

Answers (1)

belgther
belgther

Reputation: 2534

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".

Upvotes: 1

Related Questions