Exemplo n.º 1
0
  /**
   * A specialized SQL statement executor, tailored for use by {@link WebServerConnection}. Calling
   * this method fully connects the specified user, executes the specifed statement, and then
   * disconects.
   *
   * @param user the name of the user for which to execute the specified statement. The user must
   *     already exist in this Database object.
   * @param password the password of the specified user. This must match the password, as known to
   *     this Database object, of the specified user
   * @param statement the SQL statement to execute
   * @return the result of executing the specified statement, in a form already suitable for
   *     transmitting as part of an HTTP response.
   */
  byte[] execute(String user, String password, String statement) {

    Result r = null;

    try {
      Session session = connect(user, password);

      r = execute(statement, session);

      sessionManager.processDisconnect(session);

      // fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)
    } catch (SQLException e) {
      r = new Result(e.getMessage(), e.getErrorCode());
    } catch (Exception e) {
      r = new Result(e.getMessage(), Trace.GENERAL_ERROR);
    }

    try {
      return r.getBytes();
    } catch (Exception e) {
      return new byte[0];
    }
  }