상세 컨텐츠

본문 제목

jsp 답변형 게시판 java 부분

관리X 과거글

by 까먹기전에 2015. 2. 17. 17:25

본문

반응형







package board;


import java.sql.Connection;

import java.sql.DriverManager;


public class DBUtil {

public static Connection getConnection() throws Exception {

Class.forName("oracle.jdbc.OracleDriver");

String url = "jdbc:oracle:thin:@//localhost:1521/xe";

String sqlid = "scott";

String pw = "tiger";

return DriverManager.getConnection(url, sqlid, pw);

}

}

======================================================================

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;
}

}
=========================================================================================================
package board;

public class MemberVO {
String id;
String pw;
String addr;
String tel;
String email;
String je; // 제목
String na; // 내용
String writedate; //글쓴날짜
String seq;
int jo;
String comid,comna,comdate;
public String getComid() {
return comid;
}
public void setComid(String comid) {
this.comid = comid;
}
public String getComna() {
return comna;
}
public void setComna(String comna) {
this.comna = comna;
}
public String getComdate() {
return comdate;
}
public void setComdate(String comdate) {
this.comdate = comdate;
}
public int getCnt() {
return cnt;
}
public void setCnt(int cnt) {
this.cnt = cnt;
}
int cnt;
public int getJo() {
return jo;
}
public void setJo(int jo) {
this.jo = jo;
}
public String getSeq() {
return seq;
}
public void setSeq(String seq) {
this.seq = seq;
}
public String getWritedate() {
return writedate;
}
public void setWritedate(String writedate) {
this.writedate = writedate;
}
public String getNa() {
return na;
}
public void setNa(String na) {
this.na = na;
}
public String getJe() {
return je;
}
public void setJe(String je) {
this.je = je;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}

}


관련글 더보기