dao/AdminMemberDAO.java
페이지 정보
본문
package dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import model.Member;
public class AdminMemberDAO {
//사용할 객체를 미리 선언
Statement stmt;
PreparedStatement pstmt;
ResultSet rs;
DAO d = new DAO(); //d.getCon() , d.conn 사용 목적
//회원목록
public ArrayList<Member> getAllMember() {
d.getCon();
ArrayList<Member> v = new ArrayList<Member>();
try {
String sql = "select * from member";
pstmt = d.conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
Member m = new Member();
m.setId(rs.getString("id"));
m.setPass(rs.getString("pass"));
m.setName(rs.getString("name"));
m.setAge(rs.getInt("age"));
m.setGender(rs.getString("gender"));
m.setEmail(rs.getString("email"));
m.setLevel(rs.getString("level"));
v.add(m);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
rs.close();
pstmt.close();
d.conn.close();
}catch(Exception e) {
e.printStackTrace();
}
}
return v;
}
//회원 한명의 정보
public Member oneMember(String id) {
d.getCon();
Member m = new Member();
try {
String sql = "select * from member where id=?";
pstmt = d.conn.prepareStatement(sql);
pstmt.setString(1, id);
rs = pstmt.executeQuery();
if(rs.next()) {
m.setId(rs.getString("id")); //id : 데이터베이스 테이블 칼럼명
m.setPass(rs.getString("pass"));
m.setName(rs.getString("name"));
m.setAge(rs.getInt("age"));
m.setGender(rs.getString("gender"));
m.setEmail(rs.getString("email"));
m.setLevel(rs.getString("level"));
m.setMemo(rs.getString("memo"));
}
}catch(Exception e) {
e.printStackTrace();
}finally {
try {
rs.close();
pstmt.close();
d.conn.close();
}catch(Exception e) {
e.printStackTrace();
}
}
return m;
}
}
- 이전글admin/member/View.java 23.03.18
- 다음글admin/include/header_popup.jsp ( 팝업 페이지 ) 23.03.18
댓글목록
등록된 댓글이 없습니다.