2015-09-27 91 views
0

所以我試圖做一個保存按鈕來更新數據庫內的列根據什麼鍵入到其相應的文本框,但我不斷收到此錯誤「無效操作在當前光標位置「。我無法弄清楚什麼是錯誤的,因爲一切正常。誰能幫忙?提前致謝!在當前光標位置操作無效(Java DB)

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

    } 
}           
+0

檢查http://stackoverflow.com/questions/10298794/resultset-getstring1-throws-java-sql-sqlexception-invalid-operation-at-curren – user2953113

回答

0

嘗試在使用ResultSet對象之前調用rs.next()。事實上,一個新的ResultSet對象有一個指向-1的指針(默認情況下沒有結果),當您第一次調用next()方法時,它將指向第一行(如果存在),並返回true ,否則會返回false。每次你打電話時它都會嘗試指向下一行等等。