Results 1 to 2 of 2
  1. #1
    rain_shadow is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Default Invalid cursor state - no current row;

    I am very new to Java, and I am trying to complete one simple task of reading data from a table and passing it to form variables. However, I am getting this frustrating exception:

    Invalid cursor state - no current row;

    I tried everything but still no luck. I looked into Google but I'm not getting an answer that will fix this issue. Hope you guys can help.
    public class MainFrame extends javax.swing.JFrame {

    Connection con;
    Statement stm;
    ResultSet rs;

    /**
    * Creates new form MainFrame
    */
    public MainFrame() {
    initComponents();
    DoConnect();
    }

    public void DoConnect() {
    try{
    String host = "jdbc:derby:studentinfo;create=true";
    String uname = "sudeep";
    String upass = "sunny";

    con = DriverManager.getConnection(host, uname, upass);
    stm = con.createStatement();
    String sql = "SELECT * FROM APP.STUDENTID";
    rs = stm.executeQuery(sql);

    System.out.println("Query executed");

    if(rs.next())
    {
    // This is where the exception is occurring!!!!!!

    String id = rs.getString("STUDENTID");
    String first = rs.getString("FIRST_NAME");
    String second = rs.getString("SECOND_NAME");

    ID.setText(id);
    fnam1.setText(first);
    lnam.setText(second);

    System.out.println(id);
    }
    }

    catch ( SQLException err) {
    JOptionPane.showMessageDialog(MainFrame.this, err.getMessage());
    System.out.println("ERROR GETCONNECTION");}
    }
    }
    Here is the trace generated by the program run: [EL Info]: 2013-09-03 21:14:15.732--ServerSession(552364977)--EclipseLink, version: Eclipse Persistence Services - 2.5.0.v20130507-3faac2b [EL Info]: connection: 2013-09-03 21:14:16.299--ServerSession(552364977)--file:/Users/vasundhra_sudeep/NetBeansProjects/StudentForm/build/classes/_jdbc:derby:studentinfo;create=truePU login successful java.sql.SQLException: Invalid cursor state - no current row. Invalid cursor state - no current row. at org.apache.derby.impl.jdbc.SQLExceptionFactory40.g etSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.newEmbedSQLExcepti on(Unknown Source) at org.apache.derby.impl.jdbc.Util.newEmbedSQLExcepti on(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLExcep tion(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.newSQLE xception(Unknown Source) at org.apache.derby.impl.jdbc.ConnectionChild.newSQLE xception(Unknown Source) at org.apache.derby.impl.jdbc.EmbedResultSet.checkOnR ow(Unknown Source) at org.apache.derby.impl.jdbc.EmbedResultSet.getColum nType(Unknown Source) at org.apache.derby.impl.jdbc.EmbedResultSet.getStrin g(Unknown Source) at org.apache.derby.impl.jdbc.EmbedResultSet.getStrin g(Unknown Source) at studentform.MainFrame.DoConnect(MainFrame.java:57) at studentform.MainFrame.(MainFrame.java:35) at studentform.MainFrame$7.run(MainFrame.java:579) at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209) at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:715) at java.awt.EventQueue.access$400(EventQueue.java:82) at java.awt.EventQueue$2.run(EventQueue.java:676) at java.awt.EventQueue$2.run(EventQueue.java:674) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:86) at java.awt.EventQueue.dispatchEvent(EventQueue.java: 685) at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296) at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:196) at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:188) at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122) Caused by: java.sql.SQLException: Invalid cursor state - no current row. at org.apache.derby.impl.jdbc.SQLExceptionFactory.get SQLException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory40.w rapArgsForTransportAcrossDRDA(Unknown Source) ... 27 more BUILD SUCCESSFUL (total time: 7 seconds)

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,945
    Rep Power
    4

    Default Re: Invalid cursor state - no current row;

    Does this even compile?? Where are these defined?

    ID.setText(id);
    fnam1.setText(first);
    lnam.setText(second);

    Where is initComponents()?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Invalid operation at current cursor position
    By bcg9 in forum New To Java
    Replies: 4
    Last Post: 02-26-2013, 09:38 AM
  2. Replies: 2
    Last Post: 02-14-2011, 02:27 PM
  3. Replies: 4
    Last Post: 06-27-2010, 06:03 PM
  4. change the mouse cursor - crosshair cursor
    By cassysumandak in forum New To Java
    Replies: 1
    Last Post: 09-28-2009, 01:57 AM
  5. Replies: 0
    Last Post: 07-02-2009, 10:42 AM

Tags for this Thread

Posting Permissions

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