Esempio n. 1
0
  @Override
  public List<VipadVO> getVipadByMember(String member_id) {
    List<VipadVO> list = new ArrayList<VipadVO>();
    VipadVO vipadVO = null;

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    try {

      Class.forName(driver);
      con = DriverManager.getConnection(url, userid, passwd);
      pstmt = con.prepareStatement(GET_VIPAD_BY_MEMBER);
      pstmt.setString(1, member_id);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        // empVO 也稱為 Domain objects
        vipadVO = new VipadVO();
        vipadVO.setVid(rs.getInt("vid"));
        vipadVO.setMember_id(rs.getString("member_id"));
        vipadVO.setGid(rs.getInt("gid"));
        vipadVO.setJoindate(rs.getTimestamp("joindate"));
        vipadVO.setQuitdate(rs.getTimestamp("quitdate"));
        vipadVO.setStatus(rs.getInt("status"));

        list.add(vipadVO); // Store the row in the list
      }

      // Handle any driver errors
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Couldn't load database driver. " + e.getMessage());
      // Handle any SQL errors
    } catch (SQLException se) {
      throw new RuntimeException("A database error occured. " + se.getMessage());
      // Clean up JDBC resources
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException se) {
          se.printStackTrace(System.err);
        }
      }
      if (pstmt != null) {
        try {
          pstmt.close();
        } catch (SQLException se) {
          se.printStackTrace(System.err);
        }
      }
      if (con != null) {
        try {
          con.close();
        } catch (Exception e) {
          e.printStackTrace(System.err);
        }
      }
    }
    return list;
  }
Esempio n. 2
0
  @Override
  public VipadVO findByPrimaryKey(Integer vid) {

    VipadVO vipadVO = null;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    try {

      Class.forName(driver);
      con = DriverManager.getConnection(url, userid, passwd);
      pstmt = con.prepareStatement(GET_ONE_STMT);

      pstmt.setInt(1, vid);

      rs = pstmt.executeQuery();

      while (rs.next()) {
        // empVo 也稱為 Domain objects
        vipadVO = new VipadVO();
        vipadVO.setVid(rs.getInt("vid"));
        vipadVO.setMember_id(rs.getString("member_id"));
        vipadVO.setGid(rs.getInt("gid"));
        vipadVO.setJoindate(rs.getTimestamp("joindate"));
        vipadVO.setQuitdate(rs.getTimestamp("quitdate"));
        vipadVO.setStatus(rs.getInt("status"));
      }

      // Handle any driver errors
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Couldn't load database driver. " + e.getMessage());
      // Handle any SQL errors
    } catch (SQLException se) {
      throw new RuntimeException("A database error occured. " + se.getMessage());
      // Clean up JDBC resources
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException se) {
          se.printStackTrace(System.err);
        }
      }
      if (pstmt != null) {
        try {
          pstmt.close();
        } catch (SQLException se) {
          se.printStackTrace(System.err);
        }
      }
      if (con != null) {
        try {
          con.close();
        } catch (Exception e) {
          e.printStackTrace(System.err);
        }
      }
    }
    return vipadVO;
  }