我用druid监控,看到连接打开连接数大于关闭连接数。是不是连接有泄露。但是我用的是JdbcTempl的批处理接口,按理应该不会有泄露的。哪位大侠能帮我分析下不?急求解答。下面是错误日志和监控信息。
<p>
2013-12-10 17:34:52,163 ERROR [com.alibaba.druid.pool.DruidDataSource] [handleConnectionException] [1111]
</p>
discard connection
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after statement closed.
at sun.reflect.GeneratedConstructorAccessor30.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1014)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
这个是我唯一调用connection的地方,请问这个代码有连接泄露的可能吗?这个代码的作用是分析一个表的列名。
protected String[] getColumnsNameWithoutGeneratedKey(String tableName){
List<String> columnsName = new LinkedList<String>();
DatabaseMetaData dbmd = null;
Connection conn= null;
ResultSet rs = null;
try{
// 获取连接
conn = DataSourceUtils.getConnection(getDataSource());
dbmd = conn.getMetaData();
rs = dbmd.getColumns(null, null, tableName, "%");
while (rs.next()){
if ("NO".equals(rs.getString("IS_AUTOINCREMENT"))){
columnsName.add(rs.getString("COLUMN_NAME"));
}
}
}catch (Exception e) {
logger.error(e.getMessage());
throw new IllegalArgumentException(e.getMessage());
}finally{
if (rs != null){
try {
rs.close();
} catch (SQLException e) {
logger.error(e.getMessage());
}
}
// 释放连接
DataSourceUtils.releaseConnection(conn, getDataSource());
}
return columnsName.toArray(new String[0]);
}
--转自