当前光标位置的无效操作(Java DB)

时间:2015-09-27 02:07:14

标签: java netbeans

所以我正在尝试根据输入到相应文本字段的内容创建一个保存按钮来更新数据库中的列,但我不断收到此错误“当前光标位置的无效操作”。我无法弄清楚出了什么问题,因为其他一切都在运作。有人可以帮忙吗?提前谢谢!

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() );

  }
}                                        

1 个答案:

答案 0 :(得分:1)

尝试在使用ResultSet对象之前调用rs.next()。事实上,一个新的ResultSet对象有一个指向内部的指针(默认情况下没有结果),当你第一次调用next()方法它将指向第一行时,如果存在,则返回true否则会返回false。每次调用它时都会尝试指向下一行,依此类推。