반응형
Statement()
: executeQuery()로 실행할 때 파라미터로 쿼리문을 전달한다.
수행 시마다 컴파일을 하기 때문에 다중 수행 시 속도가 느리다.
ex)
public int selectCount(Connection conn) throws SQLException {
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery("select count(*) from pds_item");
rs.next();
return rs.getInt(1);
PreparedStatement()
: 실행 전에 미리 쿼리문을 컴파일 한다.
미리 컴파일해 놓은 구문을 사용하기 때문에 다중 수행 시 속도가 빠르다.
ex)
public int increaseCount(Connection conn, int id) throws SQLException {
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement("update pds_item set downloadcount = downloadcount + 1 where pds_item_id = ?");
pstmt.setInt(1, id);
return pstmt.executeUpdate();
참고 : JSP 2.1 웹프로그래밍 (PdsItemDao.java)
반응형
'Web dev' 카테고리의 다른 글
| jsp :param, :include ... flush 태그 (0) | 2022.10.31 |
|---|---|
| ORACLE SQL 시퀀스 (NEXTVAL, CURRVAL) (0) | 2022.10.29 |
| dynamic web project 클래스 컴파일 방법 (0) | 2022.10.05 |
| 이것이 자바다 4장 확인 문제 풀이 (조건문과 반복문) (0) | 2022.10.05 |
| ORACLE SQL 숫자·날짜·변환·일반·그룹함수 SCOTT 문제풀이 (0) | 2022.10.03 |