MCPcopy Index your code
hub / github.com/castello/spring_basic / selectUser

Method selectUser

ch3/UserDaoImpl.java:44–83  ·  view source on GitHub ↗
(String id)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

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