你能帮我吗,我需要将一个自动生成的密钥ADDRESS_ID插入到另一个DEBTOR表中,它是外键吗?以下是我的代码的一部分?
try {
String host = "jdbc:derby://localhost:1527/CreditManager";
String uName = "fact";
String uPass = "r107866x";
Connection con = DriverManager.getConnection(host, uName, uPass);
String query1 = "insert into ADDRESS (ADDRESS_LINE1, ADDRESS_LINE2, PROVINCE)"
+ "values (?,?,?)";
String query = "insert into DEBTOR (NATIONAL_ID, FIRSTNAME, MIDDLENAME, SURNAME,PHONE_NUMBER,DOB)"
+ "values (?,?,?,?,?,?)";
PreparedStatement preparedStatement1 = con.prepareStatement(query1);
preparedStatement1.setString(1, address_line1);
preparedStatement1.setString(2, address_line2);
preparedStatement1.setString(3, province);
preparedStatement1.executeUpdate();
PreparedStatement preparedStatement = con.prepareStatement(query);
preparedStatement.setString(1, national_id);
preparedStatement.setString(2, fname);
preparedStatement.setString(3, mname);
preparedStatement.setString(4, sname);
preparedStatement.setString(5, phone_no);
preparedStatement.setString(6, dob);
preparedStatement.executeUpdate();
// execute insert SQL stetement
} catch (SQLException ex) {
Logger.getLogger(AddAccountForm.class.getName()).log(Level.SEVERE, null, ex);
}