[Schmitzm-commits] r1728 - trunk/schmitzm-core/src/main/java/de/schmitzm/postgres
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Sep 13 17:33:33 CEST 2011
Author: alfonx
Date: 2011-09-13 17:33:33 +0200 (Tue, 13 Sep 2011)
New Revision: 1728
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java
Log:
Alle Verwendungen von ResultSet mit
try {
...
} finally {
rs.close();
}
ausgestattet.
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java 2011-09-13 14:11:22 UTC (rev 1727)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java 2011-09-13 15:33:33 UTC (rev 1728)
@@ -101,7 +101,7 @@
while (rs.next()) {
columns = LangUtil.extendArray(columns, rs.getString(1));
}
- } catch (Exception e) {
+ } finally {
rs.close();
}
} catch (SQLException e) {
@@ -172,9 +172,8 @@
ResultSet rs = c.createStatement().executeQuery(sql);
try {
return rs.next();
- } catch (Exception e) {
+ } finally {
rs.close();
- return false;
}
}
@@ -193,7 +192,7 @@
while (rs.next()) {
roles.add(rs.getString(1));
}
- } catch (Exception e) {
+ } finally {
rs.close();
}
return roles;
@@ -211,7 +210,7 @@
while (rs.next()) {
roles.add(rs.getString(1));
}
- } catch (Exception e) {
+ } finally {
rs.close();
}
return roles;
@@ -234,7 +233,7 @@
while (rs.next()) {
tables.add(rs.getString(1));
}
- } catch (Exception e) {
+ } finally {
rs.close();
}
return tables;
@@ -250,7 +249,7 @@
if (rs.next()) {
return true;
}
- } catch (Exception e) {
+ } finally {
rs.close();
}
return false;
@@ -262,7 +261,7 @@
try {
if (rs.next())
return rs.getInt(1) > 0;
- } catch (Exception e) {
+ } finally {
rs.close();
}
return false;
@@ -366,7 +365,7 @@
while (rs.next()) {
idxes.add(rs.getString(2));
}
- } catch (Exception e) {
+ } finally {
rs.close();
}
@@ -452,35 +451,39 @@
/**
* Liefert die Anzahl der offenen Sessions zur Datenbank.
- * @param c DB-Verbindung
- * @param dbName Name der Datenbank fuer die die Sessions gezaehlt
- * werden (kann {@code null} sein)
- * @param userName Name des Users fuer den die Sessions gezaehlt
- * werden (kann {@code null} sein)
+ *
+ * @param c
+ * DB-Verbindung
+ * @param dbName
+ * Name der Datenbank fuer die die Sessions gezaehlt werden (kann
+ * {@code null} sein)
+ * @param userName
+ * Name des Users fuer den die Sessions gezaehlt werden (kann
+ * {@code null} sein)
*/
public static int getOpenSessionCount(Connection c, String dbName, String userName) throws SQLException {
- String stmtSql = "SELECT COUNT(*) FROM pg_stat_activity WHERE TRUE";
-
- if ( dbName != null )
- stmtSql += " AND datname = ?";
- if ( userName != null )
- stmtSql += " AND usename = ?";
-
- PreparedStatement stmt = c.prepareStatement(stmtSql);
- if ( dbName != null )
- stmt.setString(1, dbName);
- if ( userName != null )
- stmt.setString(2, userName);
- stmt.execute();
-
- ResultSet result = stmt.getResultSet();
- int count = 0;
- if ( result.next() )
- count = result.getInt(1);
-
- result.close();
- stmt.close();
- return count;
+ String stmtSql = "SELECT COUNT(*) FROM pg_stat_activity WHERE TRUE";
+
+ if (dbName != null)
+ stmtSql += " AND datname = ?";
+ if (userName != null)
+ stmtSql += " AND usename = ?";
+
+ PreparedStatement stmt = c.prepareStatement(stmtSql);
+ if (dbName != null)
+ stmt.setString(1, dbName);
+ if (userName != null)
+ stmt.setString(2, userName);
+ stmt.execute();
+
+ ResultSet result = stmt.getResultSet();
+ int count = 0;
+ if (result.next())
+ count = result.getInt(1);
+
+ result.close();
+ stmt.close();
+ return count;
}
-
+
}
More information about the Schmitzm-commits
mailing list