• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Counting number of records in result set

 
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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The next() method will return false on the first call.
 
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
 
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSet is not null when it is empty.
 
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
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!
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic