Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-01 13:08:38
Original
1295 people have browsed it

Mysql外键

<pre name="code" class="java">//暂时关闭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);
Copy after login


Copy after login
Copy after login
Copy after login
Copy after login


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template