我创建了一个项目(我使用此教程制作:http: //www.homeandlearn.co.uk/java/save_a_new_record.html 使用此数据库: http: //www.homeandlearn.co.uk/java/java_and_databases.html )
当我想保存新记录时,程序会冻结。(我想当我保存新数据时,程序将能够使用下一个和上一个按钮工作)
我用这些代码更改了 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());
}
(清除了阻塞段(false,trues..)但现在我有这个错误:
结果集未打开。不允许进行“下一步”操作。验证自动提交是否关闭。
)