最近做一个spring版本3.0.4的老项目功能,应用场景要用到插入oracle表后返回主键ID拿来和其他表关联. 用oralce的可以一直用这种处理方式,高兼容低,搜索网上的资料都不能和这个Spring版本兼容. public long insertOraGetId(final QuetInvtHeadVO headVO) { KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStat…
DECLARE @sql nvarchar() DECLARE @cou int SET @sql='INSERT INTO people values('''+'xiaohong'+''');select @temp=@@IDENTITY' EXEC sp_executesql @sql, N'@temp int out', @cou OUT INSERT INTO child VALUES(@cou, '小兰') CREATE PROC chjj @name nvarchar() AS BE…
使用@@IDENTITY 例如:insert into student(name,age) values('fanqi',23) select @@identity 使用 OUTPUT inserted 例如:INSERT INTO UserInfo(Username,LogName,[Password],resTime) OUTPUT inserted.UserID VALUES ('12345','56789','112233',GETDATE())…
说明:MyCAT自增长主键和返回生成主键ID的实现 1) mysql本身对非自增长主键,使用last_insert_id()是不会返回结果的,只会返回0:这里做一个简单的测试 创建测试表 -------------------------------------- --创建测试表 ------------------------------------- USE test; CREATE TABLE IF NOT EXISTS t_auto_increment ( id INT NOT NULL…
insert元素 属性详解 其属性如下: parameterType ,入参的全限定类名或类型别名 keyColumn ,设置数据表自动生成的主键名.对特定数据库(如PostgreSQL),若自动生成的主键不是第一个字段则必须设置 keyProperty ,默认值unset,用于设置getGeneratedKeys方法或selectKey子元素返回值将赋值到领域模型的哪个属性中 useGeneratedKeys ,取值范围true|false(默认值),设置是否使用JDBC的getGenerea…
在开发中碰到用户注册的功能需要用到用户ID,但是用户ID是数据库自增生成的,这种情况上网查询后使用下面的方式配置mybatis的insert语句可以解决: <insert id="insert" keyProperty="id" useGeneratedKeys="true"
 parameterType="com.demo.domain.User">
 insert into User_t(name,age,ad…
使用mybatis的自动生成工具生成的主键id: <selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" > SELECT LAST_INSERT_ID()</selectKey> 使用sharding-jdbc时候 一直提示 分片报错, 可以使用这种方式解决: <insert id="insertSelective&…
1.根据useGeneratedKeys获取返回值,部分数据库不支持 修改mybatis xml 1 2 3 <insert id="insertUser" useGeneratedKeys="true" keyProperty="id" parameterType="com.entity.user">     insert into test (name) values (#{name})  </inser…
1.根据useGeneratedKeys获取返回值,部分数据库不支持 修改mybatis xml <insert id="insertUser" useGeneratedKeys="true" keyProperty="id" parameterType="com.entity.user"> insert into test (name) values (#{name}) </insert> useGe…
Q:   有时候做类似接口里的数据订正,需要取到insert语句返回的id主键,在程序里通过对象返回好取,但是写sql怎么取到呢? A:  用select @@identity得到上一次插入记录时自动产生的ID 说明: 若插入了多个行,则会产生多个标识值,@@IDENTITY 返回最后产生的标识值 举个栗子: CREATE TABLE a (id int(255) NOT NULL auto_increment,name VARCHAR(20) NOT null,PRIMARY KEY (id)…