Esempio n. 1
0
  public HouseTable() {
    Connection con = null;
    PreparedStatement pstm = null;
    ResultSet rs = null;

    try {
      con = L1DatabaseFactory.getInstance().getConnection();
      pstm = con.prepareStatement("SELECT * FROM house ORDER BY house_id");
      rs = pstm.executeQuery();
      L1House house = null;
      while (rs.next()) {
        house = new L1House();
        house.setHouseId(rs.getInt(1));
        house.setHouseName(rs.getString(2));
        house.setHouseArea(rs.getInt(3));
        house.setLocation(rs.getString(4));
        house.setKeeperId(rs.getInt(5));
        house.setOnSale(rs.getInt(6) == 1 ? true : false);
        house.setPurchaseBasement(rs.getInt(7) == 1 ? true : false);
        house.setTaxDeadline(timestampToCalendar((Timestamp) rs.getObject(8)));
        _house.put(house.getHouseId(), house);
      }
    } catch (SQLException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(rs);
      SQLUtil.close(pstm);
      SQLUtil.close(con);
    }
  }
Esempio n. 2
0
 public void updateHouse(L1House house) {
   Connection con = null;
   PreparedStatement pstm = null;
   try {
     con = L1DatabaseFactory.getInstance().getConnection();
     pstm =
         con.prepareStatement(
             "UPDATE house SET house_name=?, house_area=?, location=?, keeper_id=?, is_on_sale=?, is_purchase_basement=?, tax_deadline=? WHERE house_id=?");
     pstm.setString(1, house.getHouseName());
     pstm.setInt(2, house.getHouseArea());
     pstm.setString(3, house.getLocation());
     pstm.setInt(4, house.getKeeperId());
     pstm.setInt(5, house.isOnSale() == true ? 1 : 0);
     pstm.setInt(6, house.isPurchaseBasement() == true ? 1 : 0);
     SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     String fm = formatter.format(house.getTaxDeadline().getTime());
     pstm.setString(7, fm);
     pstm.setInt(8, house.getHouseId());
     pstm.execute();
   } catch (SQLException e) {
     _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
   } finally {
     SQLUtil.close(pstm);
     SQLUtil.close(con);
   }
 }