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


18. There is a method getColumnCount in the JDBC API. Is there a similar method to find the number of rows in a result set?

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);

+ Recent posts