기린의 기록을 위한 공간
2.DAO 본문
package com.member.model.dao;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import static com.common.JDBCTemplate.close;
import com.member.model.vo.Member;
public class MemberDao {
private Properties prop = new Properties();
public MemberDao() {
try {
String path = MemberDao.class.getResource("/sql/member/member-
query.properties").getPath();
prop.load(new FileReader(path));
}catch(IOException e) {
e.printStackTrace();
}
}
//멤버 로그인 로직 처리
//전달받은 DB(Connection정보)에 접근해서 sql을 실행하고
//그 결과를 받아서 service에 주는 기능
public Member selectId(Connection conn, String id, String pw) {
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = prop.getProperty("selectId");
//반환해줄 멤버
Member m = null;
try {
pstmt = conn.prepareStatement(sql);
rs=pstmt.executeQuery();
pstmt.setString(1, id);
pstmt.setString(2, pw);
if(rs.next()) {
m = new Member();
//인덱스 번호로 불러도되지만 안정성,
//정확성이 떨어지므로 컬럼이름으로 쓰는것이 좋다
m.setUserId(rs.getString("userid"));
m.setPassword(rs.getString("password"));
m.setUserName(rs.getString("username"));
m.setGender(rs.getString("gender"));
m.setAge(rs.getInt("age"));
m.setEmail(rs.getString("email"));
m.setPhone(rs.getString("phone"));
m.setAddress(rs.getString("address"));
m.setHobby(rs.getString("hobby"));
m.setEnrollDate(rs.getDate("enrolldate"));
}
}catch(SQLException e) {
e.printStackTrace();
}finally {
close(rs);
close(pstmt);
}
return m;
}
}
[member-query-properties]
selectId = SELECT * FROM MEMBER WHERE USERID =? AND PASSWORD=?
'Programming > JDBC' 카테고리의 다른 글
6.msg.jsp (0) | 2020.02.21 |
---|---|
5.LoginServlet (0) | 2020.02.21 |
4. VO (0) | 2020.02.21 |
3.Service (0) | 2020.02.21 |
1.JDBCTemplate (0) | 2020.02.21 |