当前位置:Gxlcms > mysql > jdbcTemplate操作MYSQL数据库时有外键约束无法插入或删除_MySQL

jdbcTemplate操作MYSQL数据库时有外键约束无法插入或删除_MySQL

时间:2021-07-01 10:21:17 帮助过:14人阅读

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);


                    

人气教程排行