Chap 3. 데이터로 작업하기
스프링 인 액션(5판) 챕터 3장을 요약한 내용 입니다.
절차
JDBC를 사용해서 데이터 읽고 쓰기
@Override
public Ingredient findById(String id) {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
connection = dataSource.getConnection();
statement = connection.prepareStatement(
"select id, name, type from Ingredient");
statement.setString(1, id);
resultSet = statement.executeQuery();
Ingredient ingredient = null;
if(resultSet.next()) {
ingredient = new Ingredient(
resultSet.getString("id"),
resultSet.getString("name"),
Ingredient.Type.valueOf(resultSet.getString("type")));
}
return ingredient;
} catch (SQLException e) {
// ??? What should be done here ???
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {}
}
}
return null;
}스키마 정의하고 데이터 추가하기
@SessionAttributes는 왜 사용할까?
스프링 데이터 JPA를 사용해서 데이터 저장하고 사용하기
JPA 리퍼지터리 커스터마이징하기
Last updated