Ejemplo n.º 1
0
 private void insertCricketer(Cricketer cricketer) {
   try {
     String stmtInsert = String.format(STATEMENT_INSERT, "cricketers", "?,?");
     PreparedStatement stmt = prepareStatement(stmtInsert);
     stmt.setLong(1, cricketer.getId());
     stmt.setLong(2, cricketer.getBattingAverage());
     stmt.executeUpdate();
   } catch (SQLException e) {
     throw new AppRuntimeException(e);
   }
 }
Ejemplo n.º 2
0
  public Player find(long id) {
    try {
      ResultSet playerRs = findRow(id, "players");
      String name = playerRs.getString("name");
      String typeString = playerRs.getString("type");

      TYPE type = TYPE.valueOf(typeString);
      switch (type) {
        case FOOTBALL:
          {
            ResultSet footBallRs = findRow(id, "footballers");
            FootBaller footBaller = new FootBaller();
            footBaller.setId(id);
            footBaller.setName(name);
            String club = footBallRs.getString("club");
            footBaller.setClub(club);
            return footBaller;
          }
        case CRICKET:
          {
            ResultSet cricketRs = findRow(id, "cricketers");
            Cricketer criketer = new Cricketer();
            criketer.setId(id);
            criketer.setName(name);
            long battingAverage = cricketRs.getLong("batting_average");
            criketer.setBattingAverage(battingAverage);
            return criketer;
          }
        case BOWLING:
          {
            ResultSet bowlingRs = findRow(id, "bowlers");
            ResultSet cricketRs = findRow(id, "cricketers");
            Bowler bowler = new Bowler();
            bowler.setId(id);
            bowler.setName(name);
            long battingAverage = cricketRs.getLong("batting_average");
            long bowlingAverage = bowlingRs.getLong("bowling_average");
            bowler.setBattingAverage(battingAverage);
            bowler.setBowlingAverage(bowlingAverage);
            return bowler;
          }
        default:
          throw new AppRuntimeException("unknown type");
      }
    } catch (SQLException e) {
      throw new AppRuntimeException(e);
    }
  }
Ejemplo n.º 3
-2
 private void updateCricketer(Cricketer cricketer) {
   try {
     String stmtUpdate = String.format(STATEMENT_UPDATE, "cricketers", "batting_average=?");
     PreparedStatement stmt = prepareStatement(stmtUpdate);
     stmt.setLong(1, cricketer.getBattingAverage());
     stmt.setLong(2, cricketer.getId());
     stmt.executeUpdate();
   } catch (SQLException e) {
     throw new AppRuntimeException(e);
   }
 }