//插入一条数据 $sql = "INSERT INTO `table_name` (`name`,age) VALUES ('小明','23')"; $dsql->SetQuery($sql);//格式化查询语句 $dsql->ExecNoneQuery();//执行SQL操作 $lastInsertID = $dsql->GetLastID(); //获取插入后的最后的ID…
MyBatis 插入时返回刚插入记录的主键值 一.要求: 1.数据库表中的主键是自增长的,如:id: 2.获取刚刚插入的记录的id值: 二.源代码: 1.User.java package cn.com.zfc.model; public class User { private Integer id; private String name; private String password; public Integer getId() { return id; } public void s…
--创建数据库和表create database MyDataBaseuse MyDataBase create table mytable(id int identity(1,1),name varchar(20)) --执行这个SQL,就能查出来刚插入记录对应的自增列的值insert into mytable values('李四')select @@identity 二.三种方式的比较 SQL Server 2000中,有三个比较类似的功能:他们分别是:SCOPE_IDENTITY.IDE…
mapper Integer insertConfigAndGetId(CrawlerConfig config); xml <insert id="insertConfigAndGetId" parameterType="com.suning.epp.fmasosadmin.dmo.CrawlerConfig"> <selectKey keyProperty="id" order="AFTER" resul…
处理方法在某个字段上加上identity id int identity(1,1), 创建标识的三种方法及比较: SQL Server 2000中,有三个比较类似的功能:他们分别是:SCOPE_IDENTITY. IDENT_CURRENT 和 @@IDENTITY,它们都返回插入到 IDENTITY 列中的值. IDENT_CURRENT 返回为任何会话和任何作用域中的特定表最后生成的标识值.IDENT_CURRENT 不受作用域和会话的限制,而受限于指定的表.IDENT_CURRENT 返回…
有时候插入记录之后需要使用到插入记录的主键,通常是再查询一次来获取主键,但是MyBatis插入记录时可以设置成返回主键id,简化操作,方法大致有两种. 对应实体类: public class User { private int userId; private String userName; private int userAge; } 对应DAO类: public interface UserMapper { int save(User user); } 方法一.使用useGenerated…
调用游标下的lastrowid 可以获取插入之前的表里id字段存放到哪个自增id cursor.lastrowid mysql> select * from userinfo; +----+-------+-----+ | id | name | pwd | +----+-------+-----+ | 1 | mike | 123 | | 2 | jack | 456 | | 3 | alex | 555 | | 4 | peter | 989 | | 5 | app | 123 | | 6…
<insert id="save" parameterType="Vote" useGeneratedKeys="true" keyProperty="id"> INSERT INTO vote VALUES(null,#{theme},#{isuse}) <selectKey resultType="int" order="AFTER" keyProperty=&qu…
<insert id="save" parameterType="Vote" useGeneratedKeys="true" keyProperty="id"> INSERT INTO vote VALUES(null,#{theme},#{isuse}) <selectKey resultType="int" order="AFTER" keyProperty=&qu…
insert into tabls1(row1,row1) values('0','0') select @@IDENTITY…