13

我在这里发布了一个查询 ,运行休眠查询后出现此错误,我不知道这是什么意思。所以几分钟后我重新运行查询,然后我没有错误,但我想知道我是如何得到它以及如何修复它。

WARN  com.mchange.v2.c3p0.impl.NewPooledConnection - [c3p0] A PooledConnection that has already signalled a Connection error is still in use!
WARN  com.mchange.v2.c3p0.impl.NewPooledConnection - [c3p0] Another error has occurred [ java.sql.SQLException: Invalid state, the Connection object is closed. ] which will not be reported to listeners!
java.sql.SQLException: Invalid state, the Connection object is closed.
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.checkOpen(ConnectionJDBC2.java:1713)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.clearWarnings(ConnectionJDBC2.java:2020)
    at com.mchange.v2.c3p0.impl.NewProxyConnection.clearWarnings(NewProxyConnection.java:933)
    at org.hibernate.util.JDBCExceptionReporter.handleAndClearWarnings(JDBCExceptionReporter.java:71)
    at org.hibernate.util.JDBCExceptionReporter.logAndClearWarnings(JDBCExceptionReporter.java:49)
    at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:472)
    at org.hibernate.jdbc.ConnectionManager.aggressiveRelease(ConnectionManager.java:429)
    at org.hibernate.jdbc.ConnectionManager.afterStatement(ConnectionManager.java:304)
    at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:572)
    at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:291)
    at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:307)
    at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:234)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1967)
    at org.hibernate.loader.Loader.doQuery(Loader.java:802)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2533)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
org.hibernate.exception.JDBCConnectionException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:2536)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
Caused by: java.sql.SQLException: I/O Error: Software caused connection abort: recv failed
    at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1053)
    at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:465)
    at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:778)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    at org.hibernate.loader.Loader.doQuery(Loader.java:802)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2533)
    ... 8 more
Caused by: java.net.SocketException: Software caused connection abort: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at java.io.DataInputStream.readFully(DataInputStream.java:195)
    at java.io.DataInputStream.readFully(DataInputStream.java:169)
    at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:842)
    at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java:723)
    at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.java:466)
    at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:103)
    at net.sourceforge.jtds.jdbc.ResponseStream.peek(ResponseStream.java:88)
    at net.sourceforge.jtds.jdbc.TdsCore.wait(TdsCore.java:3932)
    at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1046)
    ... 16 more

更新 :

我的第一个代码:

Session session = getSessionfactory().openSession();
session.beginTransaction();

ArrayList<Object[]> results = null;
try {
    StringBuilder sb = new StringBuilder();
    sb.append("select p from person p ");
    sb.append("where CONTAINS(p.name , :myName) ");

    Query q = session.createSQLQuery(sb.toString());
    String myName = "Bob Jones";
    q.setString("myName", "*" + myName + "*");  

    results = (ArrayList<Object[]>) q.list();

} catch (Exception e) {
    logger.error("Error : ", e);
} finally {
    session.close();
}

它不起作用,要修复它, 这是第二个版本:

Session session = getSessionfactory().openSession();
session.beginTransaction();

ArrayList<Object[]> results = null;
try {
    StringBuilder sb = new StringBuilder();
    sb.append("select p from person p ");
    sb.append("where CONTAINS(p.name , :myName) ");

    Query q = session.createSQLQuery(sb.toString());
    String myName = "Bob Jones";
    q.setString("myName", "\"*" + myName + "*\""); 

    results = (ArrayList<Object[]>) q.list();

} catch (Exception e) {
    logger.error("Error : ", e);
} finally {
    session.close();
}

尝试运行第二个版本,我有上面的错误。

4

5 回答 5

10

您的事务管理和/或连接管理代码可能已关闭。似乎您在出错后没有释放与连接池的连接,并试图重用它。这可能是由于您使用了错误的异常处理习惯。

于 2013-01-02T11:30:57.570 回答
1

通过使用 jTDS,您可能正在尝试连接到 MS SQL 或 Sybase。根据您发布的代码,一切看起来都很好。我建议您升级驱动程序并提高日志记录级别以获取更多详细日志。

于 2013-02-05T05:47:25.003 回答
0

添加我的 2 美分,似乎与数据库的网络连接存在一些问题。

原因:java.sql.SQLException:I/O 错误:软件导致连接中止:recv 失败

还尝试使用另一个数据库进行测试,以便检查数据库是否可能是随机发生的原因。

于 2015-06-08T07:00:28.347 回答
0

尝试使用本地数据库工具建议的索引,这可能是由于所有其他连接都需要时间从表中获取响应并且无法建立新连接,因此连接已关闭警告。

于 2020-04-13T17:19:10.493 回答
0

如果您的池空闲超时(使用测试查询检查连接)在数据库连接超时(没有从客户端听到任何消息)之前运行,也会发生这种情况,即数据库服务器决定删除并且客户端不知道它。

于 2015-12-18T20:26:18.750 回答