0

So I'm trying to make a save button to update the columns inside the database according to what's typed into their corresponding textfields, but I keep getting this error "Invalid operation at current cursor position". I can't figure out what's wrong since everything else is working. Can anyone help? Thanks in advance!

private void btn_saveActionPerformed(java.awt.event.ActionEvent evt) {                                         
  i = Integer.parseInt(txt_userid.getText( ));
  s = txt_pass.getText( );
  n = txt_name.getText( );
  birthdate = txt_bdate.getText();
  contactno = Integer.parseInt(txt_contact.getText());
  age = Integer.parseInt(txt_age.getText());
  email = txt_email.getText();
  address = txt_address.getText();
  gender = txt_gender.getText();

  adult = Integer.parseInt(txt_adult.getText());
  child = Integer.parseInt(txt_child.getText());
  senior = Integer.parseInt(txt_senior.getText());

  charge = Integer.parseInt(txt_charge.getText());
  travelclass = txt_travelclass.getText();
  luggage = txt_luggage.getText();

  flightID = txt_flightid.getText();
  departdate = txt_depardate.getText();
  departtime = txt_departime.getText();
  destination = txt_destination.getText();
  arrivdate = txt_arrivdate.getText();
  arrivtime = txt_arrivtime.getText();

  try{
      rs.updateInt("USERID",i);
      rs.updateString("PASSWORD",s);
      rs.updateString("USERNAME",n);
      rs.updateInt("AGE",age);
      rs.updateString("GENDER",gender);
      rs.updateString("BIRTHDATE",birthdate);
      rs.updateString("EMAIL",email);
      rs.updateInt("CONTACTNO",contactno);
      rs.updateString("ADDRESS",address);
      rs.updateString("FLIGHTID", flightID);
      rs.updateString("DEPARDATE", departdate);
      rs.updateString("DEPARTIME", departtime);
      rs.updateString("DESTINATION", destination);
      rs.updateString("TRAVELCLASS", travelclass);
      rs.updateString("LUGGAGE", luggage);
      rs.updateInt("TOTALPAY", charge);
      rs.updateInt("ADDPASSENGERSSENIOR", senior);
      rs.updateInt("ADDPASSENGERSADULT", adult);
      rs.updateInt("ADDPASSENGERSCHILD", child);
      rs.updateString("ARRIVALDATE", arrivdate);
      rs.updateString("ARRIVALTIME", arrivtime);
      rs.updateRow( );
      Refresh_RS_STMT();
      ShowAll();
      JOptionPane.showMessageDialog(AdminWindow.this,
              "Record has been saved!");
  }catch(SQLException err){
      System.out.println(err.getMessage() );

  }
}                                        
  • Check http://stackoverflow.com/questions/10298794/resultset-getstring1-throws-java-sql-sqlexception-invalid-operation-at-curren – user2953113 Sep 27 '15 at 02:13

1 Answers1

1

Try to call the rs.next() before any usage of the ResultSet object. In fact a fresh ResultSet object have a pointer inside which points to -1 (none of the results by default), when you call the next() method for the first time it will point to the first row, if exists, and returns true, otherwise it will return false. each time you call it it will try to point to the next row and so on.

Douraid Arfaoui
  • 212
  • 2
  • 6