If you are using JDBC API 2.0, you can scroll to the bottom of the resultset, and get a row number to find the total number in the record set.
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); // make sure its scrollable
ResultSet rs = stmt.executeQuery(myQuery);
rs.last(); // move the cusor to the last row
rs.getRow(); //get the row number