我希望创建一个组合的Java&;MySQL语句,该语句从MySQL表导入主键并将其设置为子表中的辅助键
这就是演出 我有三个MySQL表,版本为8.0.21: 第一个称为SIL,包含“id”(主键)、“nume”、“tip”、“descripere”列 第二,Rapoarte(报告),列“id”(主键)、“nume”、“tip”、“descriere”、“SIL”(链接到SIL表中的“id”列) 第三,Fisiere(文件),列“id”(主键)、“locatie”、“SILlink”(链接到SIL表中的“id”列)、“Raportlink”(链接到Rapoarte表中的“id”列) 现在,我基本上要做的是,当第一个表需要更新时,SIL,第二个和第三个表也需要成功更新 到目前为止,我已经取得了相当成功的成就,除了上表中的最后一列,Fisiere。。。“Raportlink”列 在执行更新操作时,首先我在“Fisiere”表中完全删除与要修改的“SIL”相关联的所有文件我希望创建一个组合的Java&;MySQL语句,该语句从MySQL表导入主键并将其设置为子表中的辅助键,java,mysql,Java,Mysql,这就是演出 我有三个MySQL表,版本为8.0.21: 第一个称为SIL,包含“id”(主键)、“nume”、“tip”、“descripere”列 第二,Rapoarte(报告),列“id”(主键)、“nume”、“tip”、“descriere”、“SIL”(链接到SIL表中的“id”列) 第三,Fisiere(文件),列“id”(主键)、“locatie”、“SILlink”(链接到SIL表中的“id”列)、“Raportlink”(链接到Rapoarte表中的“id”列) 现在,我基本上
[fisierManagement.deleteBySil(selecteazaSIL.getId();]
,然后使用.save(Fisier实体)重新插入它们,并使用全新的“id”;增强for循环中的方法
“SILlink”列已成功更新
然而,“Raportlink”列首先设置为“0”,然后设置为“null”,这实际上意味着该列没有从“raporate”表中的“id”列导入正确的值。。。这就是我真正需要它做的
这是我的密码:
FisierDAO fisierManagement = new FisierDAO(db.getConnection());
SILDAO SILmag = new SILDAO(db.getConnection());
SIL selecteazaSIL = null;
SIL modificaSIL = null;
RaportDAO raportMag = new RaportDAO(db.getConnection());
Raport selecteazaRaport = null;
Raport modificaRaport = null;
List<File> dosarModCom = new ArrayList<>();
private void jBtnModificareComActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnModificareComActionPerformed
// TODO add your handling code here:
try {
if(jFileChooserModCom.getCurrentDirectory().getName().toString().equals(selecteazaSIL.getNume().toString())) {
fisierManagement.deleteBySil(selecteazaSIL.getId());
modificaSIL = SILmag.getSilDupaNume(jFileChooserModCom.getCurrentDirectory().getName().toString());
modificaSIL.setNume(jTextFieldNumeModCom.getText());
modificaSIL.setTip(jTextFieldTipModCom.getText());
modificaSIL.setDescriere(jTextAreaDescModCom.getText());
SILmag.update(modificaSIL);
jFileChooserModCom.getCurrentDirectory().renameTo(new File(jFileChooserModCom.getCurrentDirectory().getParent() +
"\\" + jTextFieldNumeModCom.getText()));
modificaRaport = new Raport(jTextFieldNumeModCom.getText(), jTextFieldTipModCom.getText(), jTextAreaDescModCom.getText(), modificaSIL.getId());
raportMag.updateBySIL(modificaRaport);
scoateSQL_fkConstr();
for(File fisiere : dosarModCom) {
fisierManagement.save(new Fisier(siluriNoi + jTextFieldNumeModCom.getText() +
"\\" + fisiere.getName().toString(), modificaSIL.getId(),
modificaRaport.getId()));
fisierManagement.updateRaportLink(modificaRaport);
}
reinitiereSQL_fkConstr();
jLabelAvertismenteModCom.setText("<html><center>Comanda " + modificaSIL.getNume() + " <br>a fost modificata cu succes!</center><html/>");
jFileChooserVizCom.rescanCurrentDirectory();
} else {
jLabelAvertismenteModCom.setText("<html><center>Doar comanda selectata<br> poate fi modificata!</center></html>");
}
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(MeniuTaburi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch(NullPointerException ex) {
jLabelAvertismenteModCom.setText("<html><center>Nu ai selectat nici o comanda!</center></html>");
}
}//GEN-LAST:event_jBtnModificareComActionPerformed
private void scoateSQL_fkConstr() {
try {
PreparedStatement stmt = db.getConnection().prepareStatement("SET FOREIGN_KEY_CHECKS = 0;");
stmt.execute();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(DLMAppStart.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}
private void reinitiereSQL_fkConstr() {
try {
PreparedStatement stmt = db.getConnection().prepareStatement("SET FOREIGN_KEY_CHECKS = 1;");
stmt.execute();
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(DLMAppStart.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}
public int updateRaportLink(Raport entity) throws SQLException {
PreparedStatement stmt = conn.prepareStatement("UPDATE fisiere SET fisiere.Raportlink = " +
"(SELECT rapoarte.id FROM rapoarte WHERE rapoarte.id = ?);");
stmt.setLong(1, entity.getId());
return stmt.executeUpdate();
}
FisierDAO-fisierManagement=new-FisierDAO(db.getConnection());
SILDAO-SILmag=new-SILDAO(db.getConnection());
SIL selecteazaSIL=null;
SIL modificaSIL=null;
RaportDAO raportMag=新的RaportDAO(db.getConnection());
Raport selecteazaRaport=null;
Raport modificaRaport=null;
List dosarModCom=new ArrayList();
私有void jbtnmodificarecompactionperformed(java.awt.event.ActionEvent evt){//GEN-FIRST:event_jbtnmodificarecompactionperformed
//TODO在此处添加您的处理代码:
试一试{
如果(jFileChooserModCom.getCurrentDirectory().getName().toString().equals)(选择eazasil.getNume().toString()){
deleteBySil(selecteazaSIL.getId());
modificaSIL=SILmag.getSilDupaNume(jFileChooserModCom.getCurrentDirectory().getName().toString());
modificaSIL.setNume(jtextfieldnumomedocom.getText());
modificaSIL.setTip(jTextFieldTipModCom.getText());
modificaSIL.setDescriptiere(jtextrareadescmodcom.getText());
SILmag.更新(修改版);
jFileChooserModCom.getCurrentDirectory().renameTo(新文件(jFileChooserModCom.getCurrentDirectory().getParent())+
“\\”+jtextfieldnumomedcom.getText());
modificaRaport=new Raport(jtextfieldnumomedcom.getText(),jTextFieldTipModCom.getText(),jtextrareadescmodcom.getText(),modificaSIL.getId());
raportMag.updateBySIL(修改端口);
scoateSQL_fkConstr();
用于(文件fisiere:dosarModCom){
保存(新的Fisier(siluriNoi+jtextfieldnumomedcom.getText())+
“\\”+fisiere.getName().toString(),modificaSIL.getId(),
modificaRaport.getId());
fisierManagement.updateRaportLink(修改端口);
}
Reiniteresql_fkConstr();
jLabelAvertismenteModCom.setText(“Comanda”+modificaSIL.getNume()+“
一次成功的修改!”;
jFileChooserVizCom.rescanCurrentDirectory();
}否则{
jLabelAvertismenteModCom.setText(“Doar comanda selectata
poate fi modificata!”);
}
}catch(SQLException-ex){
getLogger(MeniuTaburi.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}捕获(NullPointerException ex){
jLabelAvertismenteModCom.setText(“Nu ai selectat nici o comanda!”);
}
}//GEN-LAST:已执行事件更改通信操作
私有void scoateSQL_fkConstr(){
试一试{
PreparedStatement stmt=db.getConnection().prepareStatement(“设置外键检查=0;”);
stmt.execute();
}catch(SQLException-ex){
java.util.logging.Logger.getLogger(DLMAppStart.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}
}
私有void reinitiereSQL_fkConstr(){
试一试{
PreparedStatement stmt=db.getConnection().prepareStatement(“设置外键检查=1;”);
stmt.execute();
}catch(SQLException-ex){
java.util.logging.Logger.getLogger(DLMAppStart.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}
}
public int updateRaportLink(Raport实体)引发SQLException{
PreparedStatement stmt=conn.prepareStatement(“更新fisiere集fisiere.Raportlink=”+
“(从raporate中选择raporate.id,其中raporate.id=?);”;
setLong(1,entity.getId());
返回stmt.executeUpdate();
}
请记住,“Fisiere”表只将文件路径存储为“locatie”列中的varchar(255),而不是BLOB对象
有人能而且想帮我吗?