Пример #1
0
  public boolean insert(EmailListVo vo) {
    Connection conn = null;
    PreparedStatement pstmt = null;
    int count = 0;

    try {
      conn = getConnection();

      String sql = "insert into EMAILLIST values(seq_emaillist.nextval, ?, ?, ?, sysdate)";
      pstmt = conn.prepareStatement(sql);

      pstmt.setString(1, vo.getFirstName());
      pstmt.setString(2, vo.getLastName());
      pstmt.setString(3, vo.getEmail());

      count = pstmt.executeUpdate();

    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    } finally {
      try {
        if (pstmt != null) {
          pstmt.close();
        }
        if (conn != null) {
          conn.close();
        }
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
    return (count == 1);
  }
Пример #2
0
  public List<EmailListVo> getList() {
    List<EmailListVo> list = new ArrayList<EmailListVo>();

    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;

    try {
      conn = getConnection();
      stmt = conn.createStatement();

      String sql =
          "select no,first_name,last_name,email, to_char(reg_date, 'yyyy-mm-dd') from emaillist order by reg_date desc";

      rs = stmt.executeQuery(sql);

      while (rs.next()) {
        Long no = rs.getLong(1);
        String firstName = rs.getString(2);
        String lastName = rs.getString(3);
        String email = rs.getString(4);
        String regDate = rs.getString(5);

        EmailListVo vo = new EmailListVo();
        vo.setNo(no);
        vo.setFirstName(firstName);
        vo.setLastName(lastName);
        vo.setEmail(email);
        vo.setRegDate(regDate);

        list.add(vo);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      try {
        if (rs != null) {
          rs.close();
        }
        if (stmt != null) {
          stmt.close();
        }
        if (conn != null) {
          conn.close();
        }
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
    return list;
  }