회원가입 디비 연결하자~~~ LoginDAO
package com.shop.model;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
public class LoginDAO {
public Connection dbCon(){
//Tomcat Context로 부터 jdbc/oracle이름의 DataSource를 가져와서
//DB Connection객체를 생성해서 리턴
//이 작업을 반복해서 하지 않도록 메서드로 작성.
Connection con = null;
try{
Context ctx = new InitialContext();
Context tomcat = (Context)ctx.lookup("java:comp/env");
DataSource ds = (DataSource)tomcat.lookup("jdbc/oracle");
con = ds.getConnection();
}catch(Exception e){
e.printStackTrace();
}
return con;
}//dbCon end
public void dbClose(Connection con, Statement stat, ResultSet rs){
try{
if(con!=null) con.close();
if(stat!=null) stat.close();
if(rs!=null) rs.close();
}catch(Exception e){
e.printStackTrace();
}
}//dbClose end
public UserVo loginProc(String uid, String pwd){
Connection con = null;
PreparedStatement stat = null;
ResultSet rs = null;
String sql = "select * from userinfo where userid = ? and passwd = ?";
UserVo vo = null;
try{
con = dbCon();
stat = con.prepareStatement(sql);
stat.setString(1, uid);
stat.setString(2, pwd);
rs = stat.executeQuery();
while(rs.next()){
vo = new UserVo();
vo.setAddress(rs.getString("address"));
vo.setUserid(uid);
vo.setPasswd(pwd);
vo.setBirth(rs.getDate("birth"));
vo.setBlog(rs.getString("blog"));
vo.setEmail(rs.getString("email"));
vo.setGender(rs.getString("gender").charAt(0));
vo.setSms(rs.getString("sms").charAt(0));
vo.setLetter(rs.getString("letter").charAt(0));
vo.setPhone(rs.getString("phone"));
vo.setMobile(rs.getString("mobile"));
vo.setUsername(rs.getString("username"));
}//while end
}catch(Exception e){
e.printStackTrace();
}finally{
dbClose(con,stat,rs);
}
return vo;
}//loginCheck() end
}