When jdbcTemplate is used to operate MYSQL databases, foreign key constraints cannot be inserted or deleted.
// Temporarily disable the mysql foreign key check function. FOREIGN_KEY_CHECKS = 0, indicating that the foreign key String closeForeignKey = "SET @ ORIG_FOREIGN_KEY_CHECKS =@foreign_key_checks, FOREIGN_KEY_CHECKS = 0 "; integer close = jdbcTemplate. update (telephone); // execute your own SQL statement String branchSql = "insert into telephone (branch_id, branch_code, branch_name, telephone, 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); // enable the mysql foreign key check function. FOREIGN_KEY_CHECKS = 1, which indicates checking the foreign key closeForeignKey = "SET @ counter = @ FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS = 1 "; integer open = jdbcTemplate. update (closeForeignKey );