The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.sql  [73 examples] > Scrollable Result Sets  [6 examples]

e271. Getting the Number of Rows in a Table Using a Scrollable Result Set

This example gets the number of rows in a scrollable result set by moving the cursor to the last row of the result set and then calling ResultSet.getRow().
    try {
        // Create a scrollable result set
        Statement stmt = connection.createStatement(
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table");
    
        // Move to the end of the result set
        resultSet.last();
    
        // Get the row number of the last row which is also the row count
        int rowCount = resultSet.getRow();
    } catch (SQLException e) {
    }

 Related Examples
e266. Determining If a Database Supports Scrollable Result Sets
e267. Creating a Scrollable Result Set
e268. Determining If a Result Set Is Scrollable
e269. Moving the Cursor in a Scrollable Result Set
e270. Getting the Cursor Position in a Scrollable Result Set

See also: Batching    Connections    Database Meta Data    Deleting Data    Drivers    Importing and Exporting    Inserting and Updating Data    Oracle OBJECTs    Oracle VARRAYs    Procedures and Functions    Retrieving Data    Tables    Updatable Result Sets   


© 2002 Addison-Wesley.