嗨,我是 java db netbeans 的初学者。,
我有两个表,即交易表和交易表中的检查表我有名为 [transID]、[PayToOrder]、[BankCode]、[Checknumber] 的列。在支票表中,我有名为 [checknumber]、[dateissued]、[amount]、[transID] 的列。我正在使用表格作为条目。
这是我用来在数据库中插入数据的代码块。
private void btnAddRecordActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String trID = txtTransID.getText();
int ID = Integer.parseInt(trID);
String pto = txtPtO.getText();
String bc = txtBankCode.getText();
String cn = txtCheckNum.getText();
int chNum = Integer.parseInt(cn);
String amount = txtAmount.getText();
int amnt = Integer.parseInt(amount);
String dates = (String) txtDate.getValue();
try{
stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql1 = "Select * From transactions";
String sql2 = "Select * From checks";
rs1 = stmt1.executeQuery(sql1);
rs2 = stmt2.executeQuery(sql2);
rs1.moveToInsertRow();
rs2.moveToInsertRow();
rs1.updateInt("transID", ID);
rs1.updateString("PAYTOORDER", pto);
rs1.updateString("BANKCODE", bc);
rs1.updateInt("checknumber", chNum);
rs2.updateInt("checknumber", chNum);
rs2.updateInt("AMOUNT", amnt);
rs2.updateString("DATEISSUED", dates);
rs2.updateInt("transID", ID);
rs1.insertRow();
rs2.insertRow();
stmt1.close();
stmt2.close();
rs1.close();
rs2.close();
JOptionPane.showMessageDialog(this, "Successfully Recorded!");
}
catch(SQLException err){
JOptionPane.showMessageDialog(this, err.getMessage());
}
}
我不断收到错误:
“在表 'TRANSACTIONS' 上插入导致违反外键约束 'CHECKNUMBER' 键(输入数据)。
请如果有人能在这方面启发我
谢谢
隆美尔安藤