Java:MySQL连接不会关闭

时间:2017-02-24 20:30:12

标签: java mysql

我无法使用DriverManager.getConnection(包java.sql)关闭我正在使用的连接。查询成功,但close()挂起,在一段时间后显示这些错误:

Counted: 19020 rsvps.
About to close connection
[WARNING] thread Thread[Abandoned connection cleanup thread,5,recmeet.tester.RecmeetSqlTester] was interrupted but is still alive after waiting at least 15000msecs
[WARNING] thread Thread[Abandoned connection cleanup thread,5,recmeet.tester.RecmeetSqlTester] will linger despite being asked to die via interruption
[WARNING] NOTE: 1 thread(s) did not finish despite being asked to  via interruption. This is not a problem with exec:java, it is a problem with the running code. Although not serious, it should be remedied.
[WARNING] Couldn't destroy threadgroup org.codehaus.mojo.exec.ExecJavaMojo$IsolatedThreadGroup[name=recmeet.tester.RecmeetSqlTester,maxpri=10]
java.lang.IllegalThreadStateException

这是代码:

Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
conn = DriverManager.getConnection("jdbc:mysql://0.0.0.0:3306/recmeet", "alexis","password");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select count(*) from rsvp;");
rs.next();
int resultInt = rs.getInt(1);
System.out.println("Counted: " + resultInt + " rsvps.");
rs.close();
stmt.close();
if (conn != null && !conn.isClosed()) {
    System.out.println("About to close connection");
    try {
        conn.close();
    }
    catch(SQLException e) {
        System.err.println("SQL exception: " + e.getMessage());
        System.exit(1);
    }
}

数据库是商品Fedora Linux盒子上的MySQL 5.7.17,my-sql-connector版本6.0.5。

0 个答案:

没有答案