[Schmitzm-commits] r1750 - trunk/schmitzm-core/src/main/java/de/schmitzm/postgres
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Oct 4 17:55:34 CEST 2011
Author: alfonx
Date: 2011-10-04 17:55:33 +0200 (Tue, 04 Oct 2011)
New Revision: 1750
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java
Log:
Mehr try finally f?\195?\188r ResultSets
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java 2011-10-04 12:45:47 UTC (rev 1749)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java 2011-10-04 15:55:33 UTC (rev 1750)
@@ -567,13 +567,16 @@
stmt.execute();
ResultSet result = stmt.getResultSet();
- int count = 0;
- if (result.next())
- count = result.getInt(1);
+ try {
+ int count = 0;
+ if (result.next())
+ count = result.getInt(1);
- result.close();
- stmt.close();
- return count;
+ return count;
+ } finally {
+ result.close();
+ stmt.close();
+ }
}
/**
@@ -597,7 +600,11 @@
+ "' and table_name = '" + viewName + "' LIMIT 1";
ResultSet rs = c.createStatement().executeQuery(checkView);
- return rs.next();
+ try {
+ return rs.next();
+ } finally {
+ rs.close();
+ }
}
public static void dropViewIfExists(Connection c, String viewName) throws SQLException {
@@ -635,18 +642,22 @@
where += " and age (now(),query_start) >= interval '" + minSecondsRunning + " second' ";
}
- final String sql = "select current_query, age (now(),query_start) as qage, waiting from pg_stat_activity " + where
- + " order by qage desc";
+ final String sql = "select current_query, age (now(),query_start) as qage, waiting from pg_stat_activity "
+ + where + " order by qage desc";
ResultSet rs = c.createStatement().executeQuery(sql);
- while (rs.next()) {
- String q = rs.getString(1);
- String since = rs.getString(2);
- String waiting = rs.getString(3);
+ try {
+ while (rs.next()) {
+ String q = rs.getString(1);
+ String since = rs.getString(2);
+ String waiting = rs.getString(3);
- result.add(new String[] {q, since, waiting});
+ result.add(new String[] { q, since, waiting });
+ }
+
+ } finally {
+ rs.close();
}
-
return result;
}
More information about the Schmitzm-commits
mailing list