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

ResultSet

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi. If a user keys in a postal code that is not in the table, I want an error message to come back stating this. My problem is that I can't seem to figure out how to tell if my select statement didn't find anything. Is there a method I can use that is sort of like a getRowCount? I've tried comparing to null, but that doesn't work. I've also tried comparing the row to zero, but that doesn't get the job done either.
Any help is appreciated!!
Thanks in advance!
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Jennifer
If all you want to know is if the number they enter is in the table then try this:
SELECT count(*) FROM table WHERE zipcodeColumn = 'userValue'
That should just return an integer in the count field that you can check to see if it greater than zero. Either way you do it you should be getting a ResultSet back then just use next to see if there is a row or not. But I know you know that so I might not be understanding your question correctly.
Another option would be to turn it into an update and not really do anything in the update:
UPDATE table SET zipcodeColumn = 'userValue' WHERE zipcodeColumn = 'userValue'
That should still return an update number even if it really doesn't do anything - but that might be kind of dangerous too if the user does something strange.
Hope that helps a little bit
Dave


Dave
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Or, if you want to just check this out using your existing SQL and result set, you could just do something like:

hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kareem Qureshi
Ranch Hand

Joined: Mar 14, 2002
Posts: 102
Jennifer,
If i were u and understood ur problem(U want to check whether the entered number which is a zipcode is valid or not) use the zipcode as a type table and cache it then i dont have to go to database everytime to check it, if it does exist and then only goahead and do rest of the processing this way i will not be tying up the precious system resources.
Sorry for not giving a quick answer but for quick fix Bill suggestion is good
Kareem
Kareem Qureshi
Ranch Hand

Joined: Mar 14, 2002
Posts: 102
I meant Bear B not bill
kareem
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Thanks for the help guys!
I appreciate it!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ResultSet