海蘭我創建一個項目(我maked使用這個turtorial:http://www.homeandlearn.co.uk/java/save_a_new_record.html使用這個數據庫:http://www.homeandlearn.co.uk/java/java_and_databases.html)。在保存數據時凍結gui jdbc,爲什麼?
當我要保存程序凍結新的記錄(我想,當我保存一個新的數據,程序將能夠與next和prev按鈕WROK)
我用這些代碼更改的save_button:
private void btnSaveRecordActionPerformed(java.awt.event.ActionEvent evt) {
//...................................................................................
String first = textFirstName.getText();
String last = textLastName.getText();
String job = textJobTitle.getText();
String ID = textID.getText();
int newID = Integer.parseInt(ID);
try {
String insertSql = "INSERT INTO Workers (ID,FIRST_NAME,LAST_NAME,JOB_TITLE) VALUES(" + newID + ",'" + first + "','" + last + "','" + job + "')";
stmt.executeUpdate(insertSql);
rs.next();
int id_col = rs.getInt("ID");
String id = Integer.toString(id_col);
String first2 = rs.getString("First_Name");
String last2 = rs.getString("Last_Name");
String job2 = rs.getString("Job_Title");
textID.setText(id);
textFirstName.setText(first2);
textLastName.setText(last2);
textJobTitle.setText(job2);
} catch (SQLException err) {
System.out.println(err.getMessage());
}
(清除阻塞段(假,trues ..)但現在我有這個錯誤:
)
定義了哪個'rs'? – Reimeus
學習使用[預準備語句](http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html)。例如,以防LAST_NAME爲「O'Reilly」。 –
你可以做一個err.printStackTrace()而不是err.getMessage(),並在問題中發佈?這可能有助於發現真正的錯誤。 –