jdbcTemplate操作MYSQL数据库时有外键约束无法插入或删除_MySQL
程序员文章站
2022-06-01 13:51:35
...
Mysql外键
//暂时关闭mysql的外键检查功能,FOREIGN_KEY_CHECKS=0,表示不检查外键String closeForeignKey = "SET @ORIG_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0";Integer close = jdbcTemplate.update(closeForeignKey);//执行自己的sql语句String branchSql = "insert into scpn_branchinfo (branch_id,branch_code,branch_name,branch_secretary,contact_person,branch_create_time,branch_address,email,telephone,office_phone,create_time) values ("+presentId+",'"+maxCode+"', '"+branchinfo.getBranchName()+"', '"+branchinfo.getBranchSecretary()+"', '"+branchinfo.getContactPerson()+"', '"+branchCreateTime+"', '"+branchinfo.getBranchAddress()+"','"+branchinfo.getEmail()+"','"+branchinfo.getTelephone()+"','"+branchinfo.getOfficePhone()+"','"+currentTime+"')";jdbcTemplate.update(branchSql); //打开mysql的外键检查功能,FOREIGN_KEY_CHECKS=1,表示检查外键closeForeignKey = "SET @ORIG_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=1";Integer open = jdbcTemplate.update(closeForeignKey);
上一篇: PHP中文编码小技巧_PHP