• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Counting number of records in result set

 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I'm trying to figure out a way to see if my result set is empty (as in, the query returned no records, as in, the table is empty).
I thought maybe there was a way similar to
rsmd.getColumnCount()
Does anyone know how I could test for this?
Annette
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The next() method will return false on the first call.
 
Monty Ireland
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search the JDBC form for this topic...
Lots of good info...

------------------
Multi-Platform Database Developer
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Use
if resultset==null
{
do something
}
else
{
do something
}
hope this answers ur question
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSet is not null when it is empty.
 
Ranjit NATARAJAN
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rs = executeQuery(" ");
while(rs.next())
{
do something;
}
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No no no. I have a database with about 12 tables in it, and I need to execute a query that selects from multiple tables. The problem is, some of the tables have no records in them, because it's still in development and we haven't had time to go and fill them in. If I make a query that mentions one of these empty tables, I get no records returned.
For example.
Let's say I have these tables:
Systems
Envs (environments)
Locations
owners
If my query says:
select s.system_names, e.env_name, l.location, o.owner_name
from systems s, envs e, locations l, owners o
where env_name="bla bla bla" and
s.owner_identifier=o.identifier and
s.env_identifier=e.identifier, etc,etc
So in the systems table, there are foreign keys to all the other tables.
But when I build my query like this, I get no records because the owner table is empty.
You might be saying "well then why include the owner table?"
Because in the future, it will need to be referenced, when it starts filing up.
So, the whole point of this was that I was trying to determine whether or not a table contained records, and if it did, append that portion to the query.
Does this make sense?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do a select count(*) from the table first. Or use an outer join.
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try that! I think that's probably the simplest way.
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic