File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Result Set problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Result Set problems" Watch "Result Set problems" New topic
Author

Result Set problems

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi guys. Can anyone tell me why I am only getting the last row when I pass my ResultSet object to another class??
Here's my code:

I printed out the result set to test if it was working.(When I did this, I had the code that is passing my resultSet object to another class commented out.) I got all my records. I put back the code that passes the resultSet and tried printing my result set again. Now it only show the last record??? Am I missing something?
Thanks in advance!!
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Jennifer
I dont know if this is it or not but could it have anything to do with the type of resultset your getting back from the query?
I mean are you creating a default resultset which would be non-scrollable? I dont know how the internal cursor is maintained by theResultSet so maybe once you've started traversing it the cursor goes to the end if it is passsed into a method ?!? I dont know.
Or, is there code that you didn't post and the resultset only gets passed once you're at the end of it.


Dave
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Thanks for the reply. I think I've got it figured out. Before I pass my ResultSet object, I had to do a rs.beforeFirst() to set the cursor to the beginning of the result set. Now I am seeing all of my records.
Thanks!!
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi. I ran across another problem. Not sure what's going on. Here is my SELECT statement:
SELECT * FROM ZIP WHERE ZIP =" + s;
String s = zip.getText();
This executes great until I enter a zip code that starts with a 0. Then nothing comes back. What am I missing. Why can't my statement find the zip codes that begin with zero, but can find all the others? Does getText() strip off zeros? If so, how do I solve this problem??
Thanks in advance!!
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Jennifer
How are the zipcodes defined in the DB? I had a huge problem with that once until I realized the zip column was defined as an integer so whenever a new zip got added to the db it stripped off the leading zero.
As far as I know getText doesn't do anthing to the String it returns - can you print you query to a log file or to standard out before running it to see what it looks like.
[ March 26, 2002: Message edited by: Dave Vick ]
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi Dave. The zip codes are defined as a nVarChar data type in SQL. That shouldn't strip zeros, should it??
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
No it shouldn't. The easiest way to check is to make sure the zipcodes in the database have their zeros in front of them.
Can you print the query out before you execute it? To make sure it looks correct.
It looks like you are concatenating the zipcode your searching for to '' to make it a string. Try to do that before the query then just add the one string to the query.
Are you putting quotes around the string your looking for?
If none of those work post some more of the code and maybe I can spot something - what DB are you using by the way?
hope one of those helps
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi Dave. I printed the query out to standard out before I ran it. It looked OK. I tried your other suggestions. Still didn't work. I am using an SQL database and the datatype of the zip codes is nVarChar. Heres some more of my code. Maybe you can see something I don't!

Thanks for taking the time to help. I really appreciate it!
[ March 26, 2002: Message edited by: Jennifer Sohl ]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Jennifer
The only thing that jumps out at me right away is that there are no quotes surrounding the zip your looking for.
Try this:
String s1 = ("SELECT * FROM ZIP WHERE ZIP ='" + s + "'");
That might do the trick for you. If not let me know. Also, I'm not familiar with the SQLConnection class, are there docs for it I can check out?
hope that helps
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
The quotes did the trick!! Thank you so much for your help! I REALLY appreciate it!
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Jennifer
Glad to have helped.
Happy coding
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Result Set problems
 
Similar Threads
How to get the number of rows in a ResultSet
Looping through result set
problem retreiving values from ArrayList
Passing array of objects......ResultSet
error on get from resultset