package board;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class MemberDAO {
public int insertMember(MemberVO vo) {
int rst = 0;
Connection conn = null;
PreparedStatement ps = null;
try {
conn = DBUtil.getConnection();
String sql = "insert into member9 values(?,?,?,?,sysdate,?)";
ps = conn.prepareStatement(sql);
ps.setString(1, vo.getId());
ps.setString(2, vo.getPw());
ps.setString(3, vo.getAddr());
ps.setString(4, vo.getId());
ps.setString(5, vo.getEmail());
rst = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
return rst;
}
public int gle(MemberVO vo) {
int rst = 0;
Connection conn = null;
PreparedStatement ps = null;
try {
conn = DBUtil.getConnection();
String sql = "insert into member8 values(?,?,?,sysdate,member8_seq.nextval,1)";
ps = conn.prepareStatement(sql);
ps.setString(1, vo.getId());
ps.setString(2, vo.getJe());
ps.setString(3, vo.getNa());
rst = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
return rst;
}
public ArrayList<MemberVO> totalgle(int first, int second) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs;
ArrayList<MemberVO> list = new ArrayList<MemberVO>();
try {
conn = DBUtil.getConnection();
String sql = "select * from (select rownum cnt,id,jemok,na,writedate,seq,jo from member8 ) t where cnt between ? and ? order by seq desc";
ps = conn.prepareStatement(sql);
ps.setInt(1, first);
ps.setInt(2, second);
rs = ps.executeQuery();
while (rs.next()) {
MemberVO vo = new MemberVO();
vo.setCnt(rs.getInt(1));
vo.setSeq(rs.getString(6));
vo.setId(rs.getString(2));
vo.setJe(rs.getString(3));
vo.setNa(rs.getString(4));
vo.setWritedate(rs.getString(5));
vo.setJo(rs.getInt(7));
list.add(vo);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
return list;
}
public ArrayList<MemberVO> mygle(String id){
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs;
ArrayList<MemberVO> list = new ArrayList<MemberVO>();
try {
conn = DBUtil.getConnection();
String sql = "select * from member8 where id=?";
ps = conn.prepareStatement(sql);
ps.setString(1, id);
rs = ps.executeQuery();
while (rs.next()) {
MemberVO vo = new MemberVO();
vo.setSeq(rs.getString(5));
vo.setId(rs.getString(1));
vo.setJe(rs.getString(2));
vo.setNa(rs.getString(3));
vo.setWritedate(rs.getString(4));
vo.setJo(rs.getInt(6));
list.add(vo);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
return list;
}
public int loginCheck(String id, String pass) {
int rst = 0;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = DBUtil.getConnection();
String sql = "select * from member9 where id=?";
ps = conn.prepareStatement(sql);
ps.setString(1, id);
rs = ps.executeQuery();
if (rs.next()) {
String DBpass = rs.getString("pw");
if ((DBpass.trim()).equals((pass.trim()))) {
rst = 2; // 로그인성공
} else {
rst = 1; // 비밀번호 틀림
}
} // 아이디 없음
} catch (Exception e) {
e.printStackTrace();
} finally {
}
return rst;
}
public void jo(String num) {
int number = Integer.parseInt(num);
Connection conn = null;
PreparedStatement ps2 = null;
try {
conn = DBUtil.getConnection();
System.out.println(number);
String sql2 = "UPDATE member8 set jo=JO+1 where seq=?";
ps2 = conn.prepareStatement(sql2);
ps2.setInt(1, number);
ps2.executeQuery();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
public ArrayList<MemberVO> viewgleCom(String num){
int number = Integer.parseInt(num);
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs;
ArrayList<MemberVO> list = new ArrayList<MemberVO>();
try {
conn = DBUtil.getConnection();
String sql = "select mm.id ,mm.COM ,mm.COMMENTDATE from member8 m,member7 mm where m.seq=? and m.seq = mm.seq order by mm.COMMENTDATE desc";
ps = conn.prepareStatement(sql);
ps.setInt(1, number);
rs = ps.executeQuery();
while (rs.next()) {
MemberVO vo = new MemberVO();
vo.setComid(rs.getString(1));
vo.setComna(rs.getString(2));
vo.setComdate(rs.getString(3));
list.add(vo);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return list;
}
public ArrayList<MemberVO> viewgle(String num) {
int number = Integer.parseInt(num);
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs;
ArrayList<MemberVO> list = new ArrayList<MemberVO>();
try {
conn = DBUtil.getConnection();
String sql = "select * from member8 where seq=?";
ps = conn.prepareStatement(sql);
ps.setInt(1, number);
rs = ps.executeQuery();
while (rs.next()) {
MemberVO vo = new MemberVO();
vo.setId(rs.getString(1));
vo.setJe(rs.getString(2));
vo.setNa(rs.getString(3));
vo.setWritedate(rs.getString(4));
vo.setSeq(rs.getString(5));
list.add(vo);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return list;
}
public String chkid(String id) {
String rst = "";
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = DBUtil.getConnection();
String sql = "select id from member9 where id=?";
ps = conn.prepareStatement(sql);
ps.setString(1, id);
rs = ps.executeQuery();
if (rs.next()) {
rst = rs.getString(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return rst;
}
public int totalrow() {
int rst = 0;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = DBUtil.getConnection();
String sql = "select max(rownum) from member8";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
rst = rs.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return rst;
}
public int comment(String num,String id,String na) {
int number = Integer.parseInt(num);
int rst=0;
Connection conn = null;
PreparedStatement ps2 = null;
try {
conn = DBUtil.getConnection();
System.out.println(number);
String sql2 = "insert into member7 values(?,?,sysdate,?)";//아이디,댓글,날짜,시퀀스
ps2 = conn.prepareStatement(sql2);
ps2.setString(1, id);
ps2.setString(2, na);
ps2.setInt(3, number);
rst=ps2.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return rst;
}
}
=========================================================================================================