Home » Java » java.net.SocketException: Socket closed: handle connection interruption

java.net.SocketException: Socket closed: handle connection interruption

Posted by: admin July 12, 2018 Leave a comment

Questions:

I have a weak connection with database server and time consuming query which is sometimes fails with exception:

Caused by: java.sql.SQLException: I/O Error: Socket closed
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2481)
    at net.sourceforge.jtds.jdbc.TdsCore.getNextRow(TdsCore.java:805)
    at net.sourceforge.jtds.jdbc.JtdsResultSet.next(JtdsResultSet.java:611)
Caused by: java.net.SocketException: Socket closed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:152)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at java.io.DataInputStream.readFully(DataInputStream.java:195)
    at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:885)
    at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java:731)
    at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.java:477)
    at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:146)
    at net.sourceforge.jtds.jdbc.TdsData.readData(TdsData.java:901)
    at net.sourceforge.jtds.jdbc.TdsCore.tdsRowToken(TdsCore.java:3175)
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2433)

How can connection interruption be handled? currently I have to manually re-run the operation until it executes successfully, maybe it could be done at jdbc driver level

ps socketTimeout property doesn’t seem to affect this

Answers: