Beispiel #1
0
  @Override
  public void saveOrUpdateResult(Result result) throws DatabaseException {
    Connection connection = null;
    PreparedStatement statement = null;

    try {
      connection = DBUtility.getConnection();

      // If result id = 0, then we are trying to save a new record, else update
      if (result.getResultId() == 0) {
        statement = connection.prepareStatement(INSERT_STMT);
        statement.setInt(1, result.getExamination().getExaminationId());
        statement.setInt(2, result.getUser().getUserId());
        statement.setInt(3, result.getNumberCorrect());
        statement.setInt(4, result.getNumberIncorrect());
        statement.setInt(5, result.getMarksObtained());
        statement.setInt(6, result.getIsPass());
        statement.executeUpdate();
      }
    } catch (ClassNotFoundException ex) {
      LOG.log(Level.SEVERE, null, ex);
      throw new DatabaseException(ex);
    } catch (SQLException ex) {
      LOG.log(Level.SEVERE, null, ex);
      throw new DatabaseException(ex);
    } finally {
      DBUtility.close(statement);
      DBUtility.close(connection);
    }
  }
Beispiel #2
0
  @Override
  public void deleteResult(Result result) throws DatabaseException {
    Connection connection = null;
    PreparedStatement statement = null;

    try {
      connection = DBUtility.getConnection();
      statement = connection.prepareStatement(DELETE_STMT);
      statement.setInt(1, result.getResultId());
      statement.execute();

    } catch (ClassNotFoundException ex) {
      LOG.log(Level.SEVERE, null, ex);
      throw new DatabaseException(ex);
    } catch (SQLException ex) {
      LOG.log(Level.SEVERE, null, ex);
      throw new DatabaseException(ex);
    } finally {
      DBUtility.close(statement);
      DBUtility.close(connection);
    }
  }