package com.shdev.user;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class UserDAO {
private Connection conn;
private PreparedStatement pstmt;
private ResultSet rs;
public UserDAO() {
try{
String dbURL = "jdbc:mysql://localhost:3306/bbs";
String dbID = "root";
String dbPassword = "root";
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(dbURL,dbID,dbPassword);
}catch(Exception e) {
e.printStackTrace();
}
}
public int login(String userID, String userPassword) {
String sql = "SELECT userPassword FROM user WHERE userID = ?";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, userID);
rs = pstmt.executeQuery();
if(rs.next()) {
if(rs.getString(1).equals(userPassword)){
return 1;
}else {
return 0;
}
}
return -1;
}catch(Exception e) {
e.printStackTrace();
}
return -2; //database err
}
public int join(User user) {
String sql = "INSERT INTO user VALUES(?,?,?,?,?)";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user.getUserID());
pstmt.setString(2, user.getUserPassword());
pstmt.setString(3, user.getUserName());
pstmt.setString(4, user.getUserGender());
pstmt.setString(5, user.getUserEmail());
return pstmt.executeUpdate();
}catch (Exception e) {
e.printStackTrace();
}
return -1;
}
}
'개인 프로젝트 > 게시판' 카테고리의 다른 글
[JSP 게시판] User.java (0) | 2018.02.03 |
---|---|
[JSP 게시판] BbsDAO.java (0) | 2018.02.03 |
[JSP 게시판] Bbs.java (0) | 2018.02.03 |
[JSP 게시판] writeAction.jsp : 게시글 작성 (0) | 2018.02.03 |
[JSP 게시판] write.jsp : 게시글 작성 (0) | 2018.02.03 |