-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
@Override
public Optional<User> findByUserIdAndUserPassword(String userId, String userPassword) {
//todo#11 -PreparedStatement- 아이디 , 비밀번호가 일치하는 회원조회
try(Connection connection = DbUtils.getConnection()){
String sql = "select * from jdbc_users where user_id= ? and user_password = ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1,userId);
preparedStatement.setString(2,userPassword);
ResultSet resultSet = preparedStatement.executeQuery();
//preparedStatement.close();
if(resultSet.next()){
User user = new User(resultSet.getString("user_id"),resultSet.getString("user_name"),resultSet.getString("user_password"));
preparedStatement.close();
return Optional.of(user);
}
return Optional.empty();
}catch(SQLException e){
log.info("Error findByUserIdAndUserPassword : {}",e.getMessage());
return Optional.empty();
}
}이거 preparedStatement.close() 주석된 부분에 처음 작성했을 때 user정보가 읽어와지지가 않는데 close하기 전데 ResultSet에 저장해놓고 close하는건데 왜 resutset정보가 왜 날아가는건지 아시나요..?
Metadata
Metadata
Assignees
Labels
No labels