Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Problem with JDBC

 
Kevin Wright
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my problem...when I run the servlet, I get the SQLException below. What's the problem? Thanks,Kevin

/***Creates SQL String and executes Query
******SQLException caught*******
* Message: Get operation not allowed. No current row
* SQLState: null
* Error Code: 0
* Date/Time: Fri Aug 03 09:27:13 EDT2001
*****************************************
*
*
*/
private void executeQuery() throws SQLException
{
String s = null;
try{
con = connectionPool.getConnection();
st = con.createStatement();
}catch(SQLException sqle){if(DEBUG){System.out.println("-------");}}
if(DEBUG){System.out.println(SQLSTATEMENT+ewoNumber);}
rs = st.executeQuery(SQLSTATEMENT+ewoNumber);//create the statement, send it out
}
 
Kevin Wright
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry...The actual SQL Statement (for an Access DB) is:
"SELECT * FROM tblLog WHERE serNumber = 233"
Thanks,
Kevin
 
Joe Wolf
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not that experienced with JDBC so this is only an observation, but "Message: Get operation not allowed. No current row" to me sounds like the ResultSet cursor isn't in the right place.
http://java.sun.com/j2se/1.3.0/docs/api/java/sql/ResultSet.html
describes all the cursor-related functions. Try moving the cursor to the beginning of the table with first() before executing the query. That's the best I can think of.
Also, out of curiosity, what is the ewoNumber for and how do you use it?
 
Phil Hanna
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You aren't showing the code that gets the exception. You've created a result set (rs) but you're probably trying to access it elsewhere. If you haven't called rs.next(), that's the problem.
BTW, your executeQuery() method doesn't declare the rs variable. If you're declaring it as an instance variable in the servlet, you've got problems. Servlets are multithreaded, and if two requests occurs at or about the same time, the second one will overlay the instance variables of the first. Don't use instance variables; either keep the variables local to a method, or save them in an HttpSession object.

------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic