File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, if you want to just check this out using your existing SQL and result set, you could just do something like:

hth,
bear
 
Kareem Qureshi
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant Bear B not bill
kareem
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help guys!
I appreciate it!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic