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 int getAllcount() {
d.getCon();
int count = 0;
try {
String sql = "select count(*) from member";
pstmt = d.conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next()) {
count = rs.getInt(1);
}
pstmt.close();
d.conn.close();
}catch(Exception e) {
e.printStackTrace();
}
return count;
}
//회원목록
public ArrayList<Member> getAllMember(int startRow, int endRow) {
d.getCon();
ArrayList<Member> v = new ArrayList<Member>();
try {
String sql = "select * from member limit ?,?";
pstmt = d.conn.prepareStatement(sql);
pstmt.setInt(1, startRow);
pstmt.setInt(2, endRow);
rs = pstmt.executeQuery();
while(rs.next()) {
Member m = new Member();
m.setId(rs.getString("id"));
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/List.java 23.03.18
- 다음글admin/member/list.jsp 23.03.18
댓글목록
등록된 댓글이 없습니다.