/**
   * DBconnectorにアクセスして管理者のIDとPASSをadminListに格納するためのメソッド
   *
   * @author Togo Akari
   * @since 2015/6/17
   * @return result
   */
  public boolean select() {
    boolean result = false;
    Connection con = DBconnector.getConnection();
    try {
      String sql = "select * from administrator";
      PreparedStatement ps = con.prepareStatement(sql);

      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        LoginAdminDTO dto = new LoginAdminDTO();
        dto.setAdminId(rs.getString(1));
        dto.setAdminPass(rs.getString(2));
        adminList.add(dto);
      }
    } catch (Exception e) {
      return result;
    } finally {
      try {
        con.close();
      } catch (Exception e) {
        return result;
      }
    }
    result = true;
    return result;
  }
示例#2
0
 /**
  * DBにHistoryの情報を格納するメソッド
  *
  * @author Yamada Kazuyuki
  * @since 2015/6/15
  * @param temporaryId 顧客識別番号
  * @param ticketName ライブ名
  * @param day 日程
  * @param salesCount 購入数
  * @param unitPrice 単価
  * @param totalAmount 小計
  * @return rsCount
  * @version 1.0
  * @see DBconnector
  */
 public int insertHistory(
     String temporaryId,
     String ticketName,
     String day,
     int salesCount,
     int unitPrice,
     long totalAmount) {
   con = DBconnector.getConnection();
   int rsCount = 0;
   try {
     String sql =
         "insert into history(temporary_id,ticket_name,day,sales_count,unit_price,total_amount) values(?,?,?,?,?,?)";
     ps = con.prepareStatement(sql);
     ps.setString(1, temporaryId);
     ps.setString(2, ticketName);
     ps.setString(3, day);
     ps.setInt(4, salesCount);
     ps.setInt(5, unitPrice);
     ps.setLong(6, totalAmount);
     rsCount = ps.executeUpdate();
     if (rsCount > 0) {
       ps.close();
       con.close();
     }
   } catch (Exception e) {
     return rsCount;
   }
   try {
     ps.close();
     con.close();
   } catch (SQLException e) {
     return rsCount;
   }
   return rsCount;
 }
示例#3
0
  /**
   * select temporaryIdの値の正誤によるselectメソッド
   *
   * @author Yamada Kazuyuki
   * @since 2015/6/9
   * @param temporaryId 顧客識別番号
   * @return result
   * @see DBconnector
   */
  public boolean select(String temporaryId) {
    boolean result = false;
    con = DBconnector.getConnection();
    try {
      String sql = "SELECT * FROM history where temporary_id=?";
      ps = con.prepareStatement(sql);
      ps.setString(1, temporaryId);

      ResultSet rs = ps.executeQuery();

      while (rs.next()) {
        result = true;
        HistoryDTO dto = new HistoryDTO();
        dto.setTemporaryId(rs.getString(1));
        dto.setTicketName(rs.getString(2));
        dto.setDay(rs.getString(3));
        dto.setSalesCount(rs.getInt(4));
        String unitPriceStr = String.format("%,d", rs.getInt(5));
        dto.setUnitPrice(unitPriceStr);
        String totalPiceStr = String.format("%,d", rs.getInt(6));
        dto.setTotalAmount(totalPiceStr);

        historyList.add(dto);
      }
    } catch (SQLException e) {
      result = false;
    } finally {
      try {
        con.close();
      } catch (SQLException e) {
        return false;
      }
    }
    return result;
  }
示例#4
0
  /**
   * delete DBconnectorにアクセスして選択された商品情報を格納するためのメソッド
   *
   * @author Yamada Kazuyuki
   * @since 2015/6/9
   * @param temporaryId 商品ID
   * @return rsCount
   * @see DBconnector
   */
  public int delete(String temporaryId) {
    con = DBconnector.getConnection();
    int rsCount = 0;
    try {
      String sql = "DELETE FROM history WHERE temporary_id=?";
      ps = con.prepareStatement(sql);
      ps.setString(1, temporaryId);
      rsCount = ps.executeUpdate();

    } catch (SQLException e) {
      return rsCount;
    }
    try {
      ps.close();
    } catch (SQLException e) {
      return rsCount;
    }
    try {
      con.close();
    } catch (SQLException e) {
      return rsCount;
    }
    return rsCount;
  }