java.sql.SQLException: Io 异常: Connection reset by peer: socket write error
at oracle.jdbc.dbaclearcase/" target="_blank" >ccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:335)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:503)
at oracle.jdbc.driver.OracleConnection.privateCreateStatement(OracleConnection.java:683)
at oracle.jdbc.driver.OracleConnection.createStatement(OracleConnection.java:560)
在没有找到办法之后,我写了一个方法, 来判断连接是否正常.
/**
* 判断连接是否正常工作
* @param connection 数据库连接对象
* @return
* @throws SQLException
*/
private boolean checkConnected(Connection connection)
throws SQLException {
// 连接为空或已经关闭
if (connection == null || connection.isClosed()) {
return (false);
}
boolean connected = false;
Statement stat = null;
try {
stat = connection.createStatement();
stat.close();
connected = true;
} catch (SQLException e) {
} finally {
try {
if (stat != null) {
stat.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return (connected);
}
在之前的连接池中, 只用了下面这句来判断.
connection == null || connection.isClosed()