--- android/TrainInfoService/src/dk/thoerup/traininfoservice/StationDAO.java 2010/02/08 19:12:15 588 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/StationDAO.java 2010/02/08 19:25:12 589 @@ -40,16 +40,22 @@ "FROM trainstations WHERE id=" + id + " AND enabled=true"; Connection conn = null; + Statement stmt = null; + ResultSet res = null; StationBean result; try { conn = DBConnection.getConnection(); - Statement stmt = conn.createStatement(); - ResultSet res = stmt.executeQuery(SQL); + stmt = conn.createStatement(); + res = stmt.executeQuery(SQL); res.next(); result = convertSingleRow(res); } finally { + if (res != null) + res.close(); + if (stmt != null) + stmt.close(); if (conn != null) conn.close(); } @@ -67,17 +73,23 @@ List result; Connection conn = null; + PreparedStatement stmt = null; + ResultSet res = null; try { conn = DBConnection.getConnection(); - PreparedStatement stmt = conn.prepareStatement(SQL); + stmt = conn.prepareStatement(SQL); stmt.setString(1, name + "%"); - ResultSet rs = stmt.executeQuery(); - result = convertResultset(rs); + res = stmt.executeQuery(); + result = convertResultset(res); } finally { - if (conn != null) + if (res != null) + res.close(); + if (stmt != null) + stmt.close(); + if (conn!= null) conn.close(); } return result; @@ -94,16 +106,22 @@ "LIMIT 4 "; List result; Connection conn = null; + PreparedStatement stmt = null; + ResultSet res = null; try { conn = DBConnection.getConnection(); - PreparedStatement stmt = conn.prepareStatement(SQL); + stmt = conn.prepareStatement(SQL); stmt.setDouble(1, latitude); stmt.setDouble(2, longitude); - ResultSet rs = stmt.executeQuery(); - result = convertResultset(rs); + res = stmt.executeQuery(); + result = convertResultset(res); } finally { - if (conn != null) + if (res != null) + res.close(); + if (stmt != null) + stmt.close(); + if (conn!= null) conn.close(); } return result; @@ -116,14 +134,20 @@ "ORDER BY name "; Connection conn = null; + Statement stmt = null; + ResultSet res = null; List result; try { conn = DBConnection.getConnection(); - Statement stmt = conn.createStatement(); - ResultSet res = stmt.executeQuery(SQL); + stmt = conn.createStatement(); + res = stmt.executeQuery(SQL); result = convertResultset(res); } finally { + if (res != null) + res.close(); + if (stmt != null) + stmt.close(); if (conn!= null) conn.close(); }