aspose file tools*
The moose likes JDBC and the fly likes ResultSet question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet question" Watch "ResultSet question" New topic
Author

ResultSet question

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I tried to execute following code,i got problem:
Statement stmt;
ResultSet rs = stmt.executeQuery("select *......");
my question is: how can i check whether any record
return or not any record return.
i check the api, it says resultset never be null value,
thanks
Tom P
Ranch Hand

Joined: May 06, 2000
Posts: 88
The ResultSet isn't pointing to a row when it is created. You have to do a rs.next() to get the first row. The rs.next() will return false if there are no more rows to get. So if nothing is returned, the first rs.next() will return false.
Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
Hi,
It's so slow when I used the rs.next(). How do I resolve it to get faster.
I'm stuck here now.
please give me a good answer.
cheers,
Paul
pmaeng@kaita.org.au
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31074
    
232

Paul,
Don't you have to do a rs.next() anyway at some point to get your data? If you don't need the data (and only want to know if the query returns results) try doing:
select count(*) from ...
This should be faster because there is less network activity.
If you do need all the fields, you need to optimize your query or your network.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
thanks for your reply earlier.
yes. I don't need any value from the table. I just check whether the record exist or not.
I was trying to use 'select count(*),,, " as well as you said. It's still too slow down.
Someone said that the resultset have to bring all row and return the value or no of row. Thus, we don't have a solution to reduce the performance through jdbc. Is that right? Urgent, i need to solve this issue if possible.
please help me.
Actually, this situation is to read all records from transaction table which has 50,000 and chain to code table whether the transaction record exist in code table or not.
if the code table has 10,000 row, this will be happen to 50,000 * 10,000 times.
thus, it could be problem. Am I right to explain?
I have to figure out this issue as soon as possible. if anyone can provide a good solution. It would be really appreciated.
thanks,
paul
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31074
    
232

Paul,
Since you don't need the data, there are two strategies for reducing the response time:
1) Faster query - Add indexes if you don't have them already. If at all possible, put an index on the columns you are joining.
2) Return less data - If count(*) is too slow, see if you can do count(fieldWithIndex). If the database can stay within the index, it should speed up the query. Also someone showed me a neat trick where you can return just the first row of a select * query. It is database specific and is slightly faster than the aggregate functions.
"Someone said that the resultset have to bring all row and return the value or no of row. Thus, we don't have a solution to reduce the performance through jdbc. Is that right?" That is correct. As mentioned above, you need to tune the query and the amount of data on the network.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet question