/** * Simple exceution method to execute a prepared-statement * * @return <code>Result</code>-Object which holds the result of the execution * @throws DatabaseException */ public ResultSet execute() throws DatabaseException { closeResult(); if (!isConnection()) throw new ParameterException("Database.execute: No active connection"); if (gQuery == null) throw new ParameterException("Database.execute: No statement to execute"); if (gPreparedStatement == null) throw new ParameterException("Database.execute: PreparedStatement was not set!\n"); try { if (gQuery.charAt(0) == 'S' || gQuery.charAt(0) == 's') gResult = gPreparedStatement.executeQuery(); else gPreparedStatement.executeUpdate(); } catch (SQLException e) { // System.err.println("Database.execute: Error while executing the // statement!\n"+gQuery+"\n"+e); closeResult(); throw new DatabaseException( "Database.execute: Error while executing the statement!\n" + gQuery + "\n" + e); } return gResult; }
/** * Simple exceution method to execute a SQL-statement * * @param pStatement SQL-String * @return <code>Result</code>-Object which holds the result of the execution * @throws DatabaseException */ public ResultSet execute(String pStatement) throws DatabaseException { closeResult(); if (!isConnection()) throw new ParameterException("Database.execute: No active connection"); try { // JDBC2 gStatement = gConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); if (pStatement.charAt(0) == 'S' || pStatement.charAt(0) == 's') gResult = gStatement.executeQuery(pStatement); else gStatement.executeUpdate(pStatement); } catch (SQLException e) { // System.err.println("Database.execute: Error while executing the // statement!\n"+pStatement+"\n"+e); throw new DatabaseException( "Database.execute: Error while executing the statement!\n" + pStatement + "\n" + e); } return gResult; }
/** Closes the current <code>Result</code> an its database connection */ public void close() { closeResult(); closeStatement(); closeConnection(); }