• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ReultSet counting rows... set to forward only?

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to count the number of rows in a ResultSet to setup a progressbar
using the following code:

and am getting the following error:

java.sql.SQLException: ResultSet was set to forward only
at org.hsqldb.jdbc.jdbcUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcResultSet.last(Unknown Source)

I'm using HSQLDB. I've written similiar code using a MySqlDB and had no issues. Is there something that must be configured in the connection to get this to work? Am I better off using a "Select count(*) ...." then doing another Resultset?

-Tad
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tad,
This is driver dependent. If you want your code to work across all databases and drivers, there are two options:
1) Do the separate select
2) If you are doing enough processing that getting the data isn't the bottleneck, you can loop through the result set and put each row in an ArrayList. Then you know how many there are and can do the processing.

If #2 is possible, I would do that. Otherwise, do #1.
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a "minimum" list of what each driver *must* support?

thank you for the info,

-Tad
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tad,
I don't know of any such list. In theory, a driver could provide stubs and no functionality at all. Obviously this wouldn't be useful.

In practice, vendors support "standard" functionality. You can do a query and loop through the result set. This is the minimum functionality to do a query, so support is required to be meaninful.
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a link to hsqldb javadocs. It looks like they support the functionality you need.

http://hsqldb.sourceforge.net/doc/src/org/hsqldb/jdbc/jdbcResultSet.html

Also, here is their support forum should the above link not help you enough:
http://sourceforge.net/forum/forum.php?forum_id=73674
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the links. Having only ever used jdbc to connect to one type of database (MySQL) I never realized how involved some of the stuff could be.


-Tad
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a quick search about this, and I'm not sure if this will help, but it's worth a try.

Try calling rs.next() before calling rs.last(). There may be a problem with the cursor not actually being 'on' a row when you start. Sounds weird, but it might be worth trying.
 
reply
    Bookmark Topic Watch Topic
  • New Topic