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

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

WBOY
WBOYOriginal
2016-06-01 13:08:381190browse

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




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn