/** * Execute an SQL update * * @param name * the DB name * @param SQL * the SQL statement * @return true if the next result is a ResultSet object; false if it is an update count or there are no more * results */ public static boolean execute(String name, String SQL) { Statement statement = null; try { statement = getConnection(name).createStatement(); if (statement != null) { return statement.execute(SQL); } } catch (SQLException ex) { throw new DatabaseException(ex.getMessage(), ex); } finally { safeCloseStatement(statement); } return false; }
/** * Execute an SQL query * * @param name * the DB name * @param SQL * the SQL statement * @return The rowSet of the query */ public static RowSet executeQuery(String name, String SQL) { Statement statement = null; ResultSet rs = null; try { statement = getConnection(name).createStatement(); if (statement != null) { rs = statement.executeQuery(SQL); } // Need to use a CachedRowSet that caches its rows in memory, which // makes it possible to operate without always being connected to // its data source CachedRowSet rowset = new CachedRowSetImpl(); rowset.populate(rs); return rowset; } catch (SQLException ex) { throw new DatabaseException(ex.getMessage(), ex); } finally { safeCloseResultSet(rs); safeCloseStatement(statement); } }