提交 3efb1b28 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Close all instances of ResultSet in PgServerThread.initDb()

上级 469a69ea
...@@ -919,17 +919,18 @@ public class PgServerThread implements Runnable { ...@@ -919,17 +919,18 @@ public class PgServerThread implements Runnable {
private void initDb() throws SQLException { private void initDb() throws SQLException {
Statement stat = null; Statement stat = null;
ResultSet rs = null;
try { try {
synchronized (server) { synchronized (server) {
// better would be: set the database to exclusive mode // better would be: set the database to exclusive mode
rs = conn.getMetaData().getTables(null, "PG_CATALOG", "PG_VERSION", null); boolean tableFound;
boolean tableFound = rs.next(); try (ResultSet rs = conn.getMetaData().getTables(null, "PG_CATALOG", "PG_VERSION", null)) {
tableFound = rs.next();
}
stat = conn.createStatement(); stat = conn.createStatement();
if (!tableFound) { if (!tableFound) {
installPgCatalog(stat); installPgCatalog(stat);
} }
rs = stat.executeQuery("select * from pg_catalog.pg_version"); try (ResultSet rs = stat.executeQuery("select * from pg_catalog.pg_version")) {
if (!rs.next() || rs.getInt(1) < 2) { if (!rs.next() || rs.getInt(1) < 2) {
// installation incomplete, or old version // installation incomplete, or old version
installPgCatalog(stat); installPgCatalog(stat);
...@@ -941,17 +942,18 @@ public class PgServerThread implements Runnable { ...@@ -941,17 +942,18 @@ public class PgServerThread implements Runnable {
} }
} }
} }
}
stat.execute("set search_path = PUBLIC, pg_catalog"); stat.execute("set search_path = PUBLIC, pg_catalog");
HashSet<Integer> typeSet = server.getTypeSet(); HashSet<Integer> typeSet = server.getTypeSet();
if (typeSet.size() == 0) { if (typeSet.size() == 0) {
rs = stat.executeQuery("select oid from pg_catalog.pg_type"); try (ResultSet rs = stat.executeQuery("select oid from pg_catalog.pg_type")) {
while (rs.next()) { while (rs.next()) {
typeSet.add(rs.getInt(1)); typeSet.add(rs.getInt(1));
} }
} }
}
} finally { } finally {
JdbcUtils.closeSilently(stat); JdbcUtils.closeSilently(stat);
JdbcUtils.closeSilently(rs);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论