public int selectInt(String query) { try { if (log != null) log.wl(query); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); if (rs.next() == false) throw new RuntimeException( "WConnection.selectInt() - No rows found for this query: " + query); int result = rs.getInt(1); rs.close(); stmt.close(); return result; } catch (SQLException e) { String message = "This query failed: " + query + "\n"; throw new RuntimeException(message, e); } }
public int executeUpdate(String query) { try { if (log != null) log.wl(query); Statement stmt = con.createStatement(); int result = stmt.executeUpdate(query); stmt.close(); return result; } catch (SQLException e) { String message = "This query failed: " + query + "\n"; throw new RuntimeException(message, e); } }
/** Execute a query on the database */ public ResultSet executeQuery(String query) { try { if (log != null) log.wl(query); Statement stmt = con.createStatement(); ResultSet result = stmt.executeQuery(query); // BUG // cannot be closed here, because RS becomes useless. // stmt.close(); return result; } catch (SQLException e) { throw new RuntimeException("This query failed: " + query + "\n", e); } }