无效的游标状态 - 没有当前行

时间:2013-09-03 01:59:37

标签: javadb

我是Java的新手,我正在尝试完成一个简单的任务,即从表中读取数据并将其传递给表单变量。但是,我遇到了这个令人沮丧的例外:

  

无效的游标状态 - 没有当前行;

我尝试了一切,但仍然没有运气。我调查了谷歌,但我没有得到解决这个问题的答案。希望你们能帮忙。

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");}
       }
   }

这是程序生成的跟踪 跑: [EL Info]:2013-09-03 21:14:15.732 - ServerSession(552364977) - EclipseLink,版本:Eclipse Persistence Services - 2.5.0.v20130507-3faac2b [EL Info]:连接:2013-09-03 21:14:16.299 - ServerSession(552364977) - file:/ Users / vasundhra_sudeep / NetBeansProjects / StudentForm / build / classes / _jdbc:derby:studentinfo; create = truePU login成功 java.sql.SQLException:无效的游标状态 - 没有当前行。 游标状态无效 - 没有当前行。     at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(未知来源)     at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(未知来源)     at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(未知来源)     在org.apache.derby.impl.jdbc.Util.generateCsSQLException(未知来源)     at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(未知来源)     at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(未知来源)     在org.apache.derby.impl.jdbc.EmbedResultSet.checkOnRow(未知来源)     at org.apache.derby.impl.jdbc.EmbedResultSet.getColumnType(Unknown Source)     at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)     at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)     在studentform.MainFrame.DoConnect(MainFrame.java:57)     在studentform.MainFrame。(MainFrame.java:35)     在studentform.MainFrame $ 7.run(MainFrame.java:579)     在java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)     at java.awt.EventQueue.dispatchEventImpl(EventQueue.java: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.doIntersectionPrivilege(AccessControlContext.java:86)     at java.awt.EventQueue.dispatchEvent(EventQueue.java:685)     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)     在java.awt.EventDispatchThread.run(EventDispatchThread.java:122) 引起:java.sql.SQLException:无效的游标状态 - 没有当前行。     at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(未知来源)     at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)     ......还有27个 建立成功(总时间:7秒)

1 个答案:

答案 0 :(得分:0)

APP.STUDENTID可能没有数据。在该表中插入至少一个记录(也就是行)数据,再次运行程序,看看是否发生了同样的异常。