Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

ResultSet question

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 41763
885
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41763
885
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic