Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    1

    Exclamation Unanswered: Invalid operation for the current cursor position

    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.

    What do I do to fix this?? the following code caused the error:

    try {
    //load the driver
    Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");

    //Get the database connection
    Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlser ver://192.168.0.110:1433;User=*****;Password=****;Databa seName=***");

    //Get a list of the project managment users
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM Users WHERE UserID = " + key + ";");

    //Get the user's info.
    String userID = new String(rs.getString("UserID"));
    String firstName = new String(rs.getString("First Name"));
    String lastName = new String(rs.getString("Last Name"));
    String title = new String(rs.getString("Title"));
    String company = new String(rs.getString("Company"));
    String emailAddress = new String(rs.getString("EmailAddress"));
    String phoneBusiness = new String(rs.getString("PhoneBusiness"));
    String fax = new String(rs.getString("Fax"));
    String phoneMobile = new String(rs.getString("PhoneMobile"));
    String office = new String(rs.getString("Office"));
    String pager = new String(rs.getString("Pager"));
    String address = new String(rs.getString("Address1"));
    String city = new String(rs.getString("City"));
    String stateOrProvince = new String(rs.getString("StateOrProvince"));
    String postalCode = new String(rs.getString("PostalCode"));
    String country = new String(rs.getString("Country"));
    out.println("<TABLE border=1><TR><TD> User ID </TD><TD colspan=3> " + userID + "</TD></TR>");
    out.println("<TR><TD> First Name </TD><TD>" + firstName + "</TD><TD> Last Name </TD><TD> " + lastName + "</TD></TR>");
    out.println("<TR><TD> Company </TD><TD>" + company + "</TD><TD> Title </TD><TD> " + title + "</TD></TR>");
    out.println("<TR><TD> E-Mail Address </TD><TD>" + emailAddress + "</TD><TD> Fax Number </TD><TD> " + fax + "</TD></TR>");
    out.println("<TR><TD> Business Phone </TD><TD>" + phoneBusiness + "</TD><TD> Mobile Phone </TD><TD> " + phoneMobile + "</TD></TR>");
    out.println("<TR><TD> Office Phone </TD><TD>" + office + "</TD><TD> Pager Number </TD><TD> " + pager + "</TD></TR>");
    out.println("<TR><TD> Address </TD><TD colspan=3> " + address + "</TD></TR>");
    out.println("<TR><TD> City </TD><TD>" + city + "</TD><TD> State Or Province </TD><TD> " + stateOrProvince + "</TD></TR>");
    out.println("<TR><TD> Postal Code </TD><TD>" + postalCode + "</TD><TD> Country </TD><TD> " + country + "</TD></TR>");
    out.println("</TABLE><A href=\"TestPageDatabaseMod\">back</a></BODY></HTML>");
    } catch( Exception e ) {
    System.err.println("Error: " + e );
    out.print("Exception: " + e );
    }

  2. #2
    Join Date
    Aug 2003
    Posts
    1

    Post

    try

    ResultSet rs = stmt.executeQuery("SELECT * FROM Users WHERE UserID = " + key + ";");

    if(rs != null && rs.next())
    {
    //Get the user's info.
    String userID = new String(rs.getString("UserID"));
    ...
    ....
    }

  3. #3
    Join Date
    Apr 2004
    Posts
    1
    had the same problem, normally people use while(rs.next()) and traverse the resultset from start to finish. rs.next() moves the cursor position from before the first set of results in the resultset, onto the first one. so if not using a while loop, just call rs.next() to move the first result

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •