### Error getting a new connection. Cause: java.sql.SQLException: I/O Error: Socket closed

1.8k Views Asked by At

Exception happened when try to openSqlSession, WHY

ERROR LOG

2017-09-27 21:14:32,409 [pool-13-thread-1] ERROR - test sql error
org.apache.ibatis.exceptions.PersistenceException: 
### Error getting a new connection.  Cause: java.sql.SQLException: I/O Error: Socket closed
### Cause: java.sql.SQLException: I/O Error: Socket closed
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.getConnection(DefaultSqlSession.java:300)

JAVA CODE

sqlSession = sqlSessionFactory.openSession(autoCommit);

DATABASE Config

<dataSource type="POOLED">
        <property name="driver" value="${driver}" />
        <property name="url" value="${url}" />
        <property name="username" value="${username}" />
        <property name="password" value="${password}" />
        <property name="poolPingEnabled" value="true" />
        <property name="poolPingQuery" value="SELECT 1" />
        <property name="poolPingConnectionsNotUsedFor" value="3600000" />
    </dataSource>   
1

There are 1 best solutions below

2
gati sahu On

A 'I/O Error: Socket closed' exception means that the connection between the JDBC client and the server was closed for some reason.

My advice will be use some connection pool library if you are not using any pool.

The reason could be one of the following:

  1. You tried to execute a query on a connection that has been closed.
  2. May be OS terminated the connection because of a network problem.
  3. Database server is shut down.
  4. Because the result is too long to be read or the query is taking lot of time to execute