| 84 | |
| 85 | // 사용자 정보를 user_info테이블에 저장하는 메서드 |
| 86 | @Override |
| 87 | public int insertUser(User user) { |
| 88 | int rowCnt = FAIL; |
| 89 | |
| 90 | Connection conn = null; |
| 91 | PreparedStatement pstmt = null; |
| 92 | |
| 93 | // insert into user_info (id, pwd, name, email, birth, sns, reg_date) |
| 94 | // values ('asdf22', '1234', 'smith', 'aaa@aaa.com', '2022-01-01', 'facebook', now()); |
| 95 | String sql = "insert into user_info values (?, ?, ?, ?,?,?, now()) "; |
| 96 | |
| 97 | try { |
| 98 | conn = ds.getConnection(); |
| 99 | pstmt = conn.prepareStatement(sql); // SQL Injection공격, 성능향상 |
| 100 | pstmt.setString(1, user.getId()); |
| 101 | pstmt.setString(2, user.getPwd()); |
| 102 | pstmt.setString(3, user.getName()); |
| 103 | pstmt.setString(4, user.getEmail()); |
| 104 | pstmt.setDate(5, new java.sql.Date(user.getBirth().getTime())); |
| 105 | pstmt.setString(6, user.getSns()); |
| 106 | |
| 107 | return pstmt.executeUpdate(); // insert, delete, update; |
| 108 | } catch (SQLException e) { |
| 109 | e.printStackTrace(); |
| 110 | return FAIL; |
| 111 | } finally { |
| 112 | close(pstmt, conn); // private void close(AutoCloseable... acs) { |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // 매개변수로 받은 사용자 정보로 user_info테이블을 update하는 메서드 |
| 117 | @Override |