B4J Question jSQL, ResultSet and (lack of) RowCount

tchart

Well-Known Member
Licensed User
Longtime User
Question;

How can I tell if a ResultSet is empty or get a row count from a ResultSet without calling NextRow?

Background;

I have an app that produces a report from several (long running) SQL queries (against SQLite)

I was running a report today and one of the queries returns no results which is acceptable but it was throwing an error when I try to get a value from the ResultSet. The error is "java.sql.SQLException: ResultSet closed".

Granted the code is not ideal and I have fixed that but...

The issue is the ResultSet is initialized, has a column count but there is no way to tell if the ResultSet contains any rows without invoking NextRow (which I don't want to do at the point in the code where the error was occuring).

There is no RowCount method on the ResultSet (jSQL 1.30).

As the query can take a long time to run I cant run the query more than once (too time consuming) and I dont want to run a separate "select count(*)" statement every time (this too is time consuming).

I tried this https://www.b4x.com/android/forum/threads/sql-rowcount.61092/#content but the ResultSet (fro SQLite) is forward only so cant be traversed this way.
 

tchart

Well-Known Member
Licensed User
Longtime User
Thanks Erel. I've already fixed code but was curious for future use if there was a way to tell if the ResultSet was empty. Looking at the official Java docs it doesnt looks like it is possible.
 
Upvote 0
Top