Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE");
rs.last(); //ResultSet의 맨 끝의 행으로 이동...
int count = rs.getRow(); //현재로우가 맨마지막 로우므로 전체건수가된다...
java.sql.ResultSet API를 보시면 자세하게 설명이 나와있습니다..
TYPE_SCROLL_INSENSITIVE
The constant indicating the type for a ResultSet object that is scrollable
but generally not sensitive to changes made by others.
TYPE_SCROLL_SENSITIVE
The constant indicating the type for a ResultSet object that is scrollable
and generally sensitive to changes made by others.
(출처 : 'java ResultSet 에 대한 레코드 건수 알아내기' - 네이버 지식iN)
-----------------------------------
출처: http://java.sun.com/products/jdbc/reference/faqs/index.html
No, but it is easy to find the number of rows. If you are using a scrollable result set, rs
, you can call the methods rs.last
and then rs.getRow
to find out how many rows rs
has. If the result is not scrollable, you can either count the rows by iterating through the result set or get the number of rows by submitting a query with a COUNT
column in the SELECT
clause.
-----------------------------------
그러면 preparedStatement 에서는 어떻게 사용하는가..
pstmt = conn.prepareStatement(sb.toString(),
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
'IT > Language' 카테고리의 다른 글
[JAVA] 숫자를 화폐단위로 변경 (0) | 2007.06.29 |
---|---|
[JAVA] 날짜 구하기 팁 (0) | 2007.06.29 |
[JAVA] 문자열중에 한글체크하기 정말 쉬워요. - getType (0) | 2007.06.29 |
[JAVA] 디렉토리 & 파일 삭제 (0) | 2007.06.29 |
[JAVA] String과 StringBuffer (0) | 2007.06.29 |