Statement
실제 DB에 쿼리를 보내기 위한 객체
ResultSet
Satatement, PreparedStatement 객체로 select문을 사용해 얻어온 레코드 값들을 테이블 형태로 갖게 되는 객체
public List<SaramDto> selectAll() throws SQLException {
List<SaramDto> list = new ArrayList<>();
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
// 레코드가 존재하지 않을 때까지 계속 레코드 행을 다음으로 이동하며 레코드 값 가져옴
while (rs.next()) {
String id = rs.getString(1);
String name = rs.getString(2);
int age = rs.getInt(3);
SaramDto saramDto = new SaramDto(id, name, age);
list.add(saramDto);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
}
return list;
}
'TIP > JSP' 카테고리의 다른 글
cookie & session (0) | 2018.09.28 |
---|---|
컨트롤러 분기문 만들기 (0) | 2018.09.27 |
한글 처리 (0) | 2018.09.26 |
커넥션풀 (0) | 2018.09.26 |
mysql jdbc 연동 (0) | 2018.09.22 |