MCPcopy Create free account
hub / github.com/castello/spring_basic / selectUser

Method selectUser

ch3/UserDao.java:43–81  ·  view source on GitHub ↗
(String id)

Source from the content-addressed store, hash-verified

41 }
42
43 public User selectUser(String id) throws Exception {
44 User user = null;
45
46 Connection conn = null;
47 PreparedStatement pstmt = null;
48 ResultSet rs = null;
49
50 String sql = "select * from user_info where id= ? ";
51
52 try {
53 conn = ds.getConnection();
54 pstmt = conn.prepareStatement(sql); // SQL Injection공격, 성능향상
55 pstmt.setString(1, id);
56
57 rs = pstmt.executeQuery(); // select
58
59 if (rs.next()) {
60 user = new User();
61 user.setId(rs.getString(1));
62 user.setPwd(rs.getString(2));
63 user.setName(rs.getString(3));
64 user.setEmail(rs.getString(4));
65 user.setBirth(new Date(rs.getDate(5).getTime()));
66 user.setSns(rs.getString(6));
67 user.setReg_date(new Date(rs.getTimestamp(7).getTime()));
68 }
69 } catch (SQLException e) {
70 return null;
71 } finally {
72 // close()를 호출하다가 예외가 발생할 수 있으므로, try-catch로 감싸야함.
73 // close()의 호출순서는 생성된 순서의 역순
74// try { if(rs!=null) rs.close(); } catch (SQLException e) { e.printStackTrace();}
75// try { if(pstmt!=null) pstmt.close(); } catch (SQLException e) { e.printStackTrace();}
76// try { if(conn!=null) conn.close(); } catch (SQLException e) { e.printStackTrace();}
77 close(rs, pstmt, conn); // private void close(AutoCloseable... acs) {
78 }
79
80 return user;
81 }
82
83 // 사용자 정보를 user_info테이블에 저장하는 메서드
84 public int insertUser(User user) {

Callers

nothing calls this directly

Implementers 1

UserDaoImplch3/UserDaoImpl.java

Calls 8

setIdMethod · 0.95
setPwdMethod · 0.95
setNameMethod · 0.95
setEmailMethod · 0.95
setBirthMethod · 0.95
setSnsMethod · 0.95
setReg_dateMethod · 0.95
closeMethod · 0.95

Tested by

no test coverage detected