我有jdbc客户端(请参阅下面的代码)定期连接到本地mariadb服务器并查询复制状态。
private void closeResultSet(ResultSet rs) {
try {
rs.close();
} catch (Exception e) {}
}
private void closeStatement (Statement st) {
try {
st.close();
} catch (Exception e) {}
}
private void closeConnection(Connection c) {
try {
c.close();
} catch (Exception e) {}
}
public boolean getStatus() {
boolean status = false;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
//Class.forName("com.mysql.jdbc.Driver");
Class.forName("org.mariadb.jdbc.Driver");
// System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
String sql = "SHOW STATUS LIKE 'wsrep_%'";
rs = stmt.executeQuery(sql);
while (rs.next()) {
String name = rs.getString(1);
String value = rs.getString(2);
if (name != null && !name.isEmpty() && value != null && !value.isEmpty())
{
System.out.println(value);
}
}
status = true;
} catch (SQLException se) {
// Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
// Handle errors for Class.forName
e.printStackTrace();
} finally {
// finally block used to close resources
closeResultSet(rs);
closeStatement(stmt);
closeConnection(conn);
} // end try
if (!status)
return status;
}
public void run()
{
while(true) {
if (!getStatus())
//failed
break;
else {
sleep 60s
}
}
}
大约3个小时后我看到
java.sql.SQLNonTransientConnectionException :( conn:17945)无法读取结果集:意外的流结束,从4读取0字节
我的代码中有什么问题吗?
我想知道“(conn:17945)”是否意味着我的关系越来越多,超出了可持续的最大数量......?