• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Error

 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to call ResultSet.next() at least once on a resultset before you can get the fields off of it.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You got it!
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic