Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to check if recordset is empty  RSS feed

 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a piece of code where I check if my recordset is empty. I use these function:



The problem that I have with these function is that when I show the results of recordset the first register dont show. I suspect that is because the "rsCheck.next"
If I put rsCheck.first(), gives me an exception.

Could you help me please?
 
Knute Snortum
Sheriff
Posts: 3612
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should be using one of the "get" methods.
 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I think you should be using one of the "get" methods.


I dont understand you, sorry :-(
 
K. Tsang
Bartender
Posts: 3639
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may just want to use



This way you don't need to set your result set back to the first row.
 
Knute Snortum
Sheriff
Posts: 3612
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the documentation for RecordSet. Several of the methods start with the letters "get", like getString(int).
 
Dave Tolls
Ranch Hand
Posts: 2554
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would question why you need to know whether the RS is empty prior to looping over its contents.
Surely it's easier to check if there were any results after you've read them?
 
Campbell Ritchie
Sheriff
Posts: 54034
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RecordSet? You would appear to mean ResultSet.

Look in the Java Tutorials. The first example shown tests whether the ResultSet it has been given is full or not. Beware: the method used there to find whether a result set is full has a side‑effect.

I think this discussion would fit better in our databases forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!