| 111 | |
| 112 | // 사용자 정보를 user_info테이블에 저장하는 메서드 |
| 113 | public int insertUser(User user) throws Exception { |
| 114 | Connection conn = ds.getConnection(); |
| 115 | |
| 116 | // insert into user_info (id, pwd, name, email, birth, sns, reg_date) |
| 117 | // values ('asdf22', '1234', 'smith', 'aaa@aaa.com', '2022-01-01', 'facebook', now()); |
| 118 | |
| 119 | String sql = "insert into user_info values (?, ?, ?, ?,?,?, now()) "; |
| 120 | |
| 121 | PreparedStatement pstmt = conn.prepareStatement(sql); // SQL Injection공격, 성능향상 |
| 122 | pstmt.setString(1, user.getId()); |
| 123 | pstmt.setString(2, user.getPwd()); |
| 124 | pstmt.setString(3, user.getName()); |
| 125 | pstmt.setString(4, user.getEmail()); |
| 126 | pstmt.setDate(5, new java.sql.Date(user.getBirth().getTime())); |
| 127 | pstmt.setString(6, user.getSns()); |
| 128 | |
| 129 | int rowCnt = pstmt.executeUpdate(); // insert, delete, update |
| 130 | |
| 131 | return rowCnt; |
| 132 | } |
| 133 | |
| 134 | @Test |
| 135 | public void springJdbcConnectionTest() throws Exception { |