aspose file tools*
The moose likes Servlets and the fly likes Counting number of records in result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Counting number of records in result set" Watch "Counting number of records in result set" New topic
Author

Counting number of records in result set

Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
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

Joined: May 05, 2000
Posts: 13974
The next() method will return false on the first call.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
Search the JDBC form for this topic...
Lots of good info...

------------------
Multi-Platform Database Developer


Multi Platform Database Developer & DBA on E.S.T.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi,
Use
if resultset==null
{
do something
}
else
{
do something
}
hope this answers ur question
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
ResultSet is not null when it is empty.
Ranjit NATARAJAN
Greenhorn

Joined: Jan 05, 2001
Posts: 7
rs = executeQuery(" ");
while(rs.next())
{
do something;
}
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
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

Joined: May 05, 2000
Posts: 13974
Do a select count(*) from the table first. Or use an outer join.
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
I'll try that! I think that's probably the simplest way.
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Counting number of records in result set