我有一些我正在维护的代码在另一个代码中进行嵌入式 JDBC 调用。这对我来说是错误的,但更重要的是我想知道这是否会导致连接泄漏?
public Table1 method1(){
String query = "SELECT id1, id2 FROM table1";
Table1 t1 = new Table();
try (Connection masterDB = getConnection();
PreparedStatement statement = masterDB.prepareStatement(query);
ResultSet result = statement.executeQuery()) {
while (result.next()) {
t1.setEntry(method2(result.getInt("id1")));
}
}
return t1;
}
public Table2 method2(){
String query = "SELECT idA, idB FROM table2";
Table2 t2 = new Table2();
try (Connection masterDB = getConnection();
PreparedStatement statement = masterDB.prepareStatement(query);
ResultSet result = statement.executeQuery()) {
while (result.next()) {
t2.setId((result.getInt("idA")));
}
}
return t2;
}