title: JDBC - Invalid Cursor State
body: <p>I am a beginner in writing programs, I have created a search record function for my assignment.</p>
  
  <pre><code>public void searchRecord(){
               for(int ct = 0; ct&lt; 1; ct++){
               System.out.println("Please insert student ID");
               System.out.print("Student ID: ");//prompt for student ID to search
               String data = k.nextLine().trim();
               String sql = "SELECT * FROM Students WHERE StudentID = '"+data+"'";
               try{
                   rs = st.executeQuery(sql);                 
               if(rs.next()){    
                   displayRecord();
                   rs.next();
                   showMenu();
               }
               else{
                   System.out.print("No record found. ");
                   ct--;
               }
               }catch (Exception ex){
                   System.out.println("Problem searching.");
               } 
               }
  </code></pre>
  
  <p>However, after I try to get data from the result, it shows <code>Invalid Cursor State</code>. 
  If I want to retrieve data, I'll have to execute the <code>Display next record</code> method which is:</p>
  
  <pre><code>try{
      if(rs.next()){
      displayRecord();
      }
  else{
      rs.previous();
      System.out.println("No more records!");
  }
  }catch (Exception ex){
  System.out.println("There is problem showing next data.");
  }
  </code></pre>
  
  <p>I tried adding "rs.next" at the search record method after "displayRecord" but it wouldn't solve the problem. Is there anyway to solve this?</p>
  
  <p>By the way my display record method:</p>
  
  <pre><code>public void displayRecord(){//get and display data from current row of record
          try{
                      String ID = rs.getString(1);
                      String fname = rs.getString(2);
                      String lname = rs.getString(3);
                      String conNo = rs.getString(4);
                      String mail = rs.getString(5);
                      String plate = rs.getString(6);
                      Date date = rs.getDate(7);
                      System.out.print("Student ID: "+ID+"\nName: "+fname+" "+lname+"\nCar Number: "+plate+"\nContact Number: 0"+conNo+"\nE-Mail Address: "+mail+"\nDate Registered: "+date);
  
          }catch (Exception ex){
              System.out.println(ex);
          }
  }
  </code></pre>
  
  <p>Any helps or advices are appreciated.</p>