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

SQL Error

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
I'm getting the following error when I try to run some of my code:
SQL error encountered: java.sql.SQLException: Before start of result set
I have some servlets that take in information, and list everything in the database into an html table. This works fine. I also want to be able to edit each line, so I have a button next to it that calls my EditServlet. All this works fine.
My database is namesDB, a table named names. I grab an ArrayList from the previous servlet session parameter with:

The system.out.println() is just to check to make sure I am grabbing the right line of the table, which it does.
I then do:

Again, the system.out.println() is there to make sure the query is properly formatted for what I want to do, which it is. I can use the same query at the mySQL prompt and pull up the appropriate row of data.
Later I do the following:

I changed the <> for the html stuff to {}, couldn't figure how to turn of html code, so it kept messing up my post.
test3 prints out, but not test4, so my error is obviously dealing with the rs.getString() method. "Name" is the appropriate heading for the first row, so it should grab the data from this field, correct? I've even tried using field values like rs.getString( 1 ), but that still didn't work.
Anyone have any suggestions?
Thanks!
Jason
[This message has been edited by jason adam (edited August 15, 2001).]
[This message has been edited by jason adam (edited August 15, 2001).]
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You have to call ResultSet.next() at least once on a resultset before you can get the fields off of it.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Ah, because the cursor is initially positioned before the selected row, calling next() makes it so that the selected row becomes the current row?
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You got it!
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Excellent!! Thank you much for the help, I got it to read the row I want to edit, and even got the updating part working beautifully.

Thanks!
Jason
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Error
 
Similar Threads
How to select HTML Table elements
Problems when viewing specific description when search
Putting a ResultSet into an Array
help with jsp
Unable to find specific product