Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Counting number of records in result set  RSS feed

 
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
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.
 
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
Ranch Hand
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
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!