ibatis插入数据返回ID的方法

主要就是利用seelctkey来获取这个ID值,但是oracle和mysql的区别还是很大的

oracle的用法

<insert id="insertOperation">

<selectKey resultClass="long" keyProperty="Id" >

select operation_seq.nextval as id from desc

</selectKey>

insert into test(id,name,desc) values (#id#,#name#,#desc#)

</insert>

oracle主要通过序列来返回insert的ID号,所以selectkey主要做的操作是从序列中拿到下一个值

mysql的用法

<insert id="insertTopic" parameterClass="topic">

insert into test(ID, NAME, DESC) values (#ID#, #NAME#, #DES#)

<selectKey resultClass="string" keyProperty="id">

select last_insert_id() as ID from test limit 1
    </selectKey>
</insert>

msyql主要利用了last_insert_id这个函数来获取最大的id值

ibatis插入数据返回ID的方法的更多相关文章

  1. mybatis 插入数据返回ID

    hibernate中插入数据后会返回插入的数据的ID,mybatis要使用此功能需要在配置文件中显示声明两个属性即可:

  2. Mybatis(spring)(多个参数)(插入数据返回id)

    一. 1.两个参数都是int类型() 例子: 1 <  select id="searchClassAllNum" resultType="int"> ...

  3. MSSQL2005后版本插入数据返回ID的新写法

    例子: INSERT VolunteerSound_Table (Title,ArticleContent)OUTPUT Inserted.ID VALUES ('FirstVal','bbbbb') ...

  4. MySQL插入数据返回id

    按照应用需要,常常要取得刚刚插入数据库表里的记录的ID值,在MYSQL中可以使用LAST_INSERT_ID()函数,在MSSQL中使用 @@IDENTITY.挺方便的一个函数.但是,这里需要注意的是 ...

  5. 使用SQLServer2005插入一条数据时返回当前插入数据的ID

    使用SQLServer2005插入一条数据时返回当前插入数据的ID 在执行完插入后 再执行 select @@identity from users 就OK 就是刚才插入的那行的 ID了 补充: @@ ...

  6. SQL Server返回插入数据的ID和受影响的行数

    首先看看数据库里面的数据(S_Id为自增长标识列): sql server 中返回上一次插入数据的ID(标识值)有三种方式: 第一种 @@IDENTITY: insert into Student(S ...

  7. SQLServer 批量插入数据的两种方法

    SQLServer 批量插入数据的两种方法-发布:dxy 字体:[增加 减小] 类型:转载 在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Ins ...

  8. SQL 2005批量插入数据的二种方法

    SQL 2005批量插入数据的二种方法 Posted on 2010-07-22 18:13 moss_tan_jun 阅读(2635) 评论(2) 编辑 收藏 在SQL Server 中插入一条数据 ...

  9. 触发器修改后保存之前的数据 表中插入数据时ID自动增长

    create or replace trigger t before update on test5 for each rowbegin insert into test55 values (:old ...

随机推荐

  1. 回调函数callback

    你到一个商店买东西,刚好你要的东西没有货,于是你在店员那里留下了你的电话,过了几天店里有货了,店员就打了你的电话,然后你接到电话后就到店里去取了货.在这个例子里,你的电话号码就叫回调函数,你把电话留给 ...

  2. Encode and Decode Strings

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  3. Java for LeetCode 147 Insertion Sort List

    Sort a linked list using insertion sort. 解题思路: 插入排序,JAVA实现如下: public ListNode insertionSortList(List ...

  4. mybatis There is no getter for property named 'xx' in 'class java.lang.String

    转载自://http://www.cnblogs.com/anee/p/3324140.html 用mybatis查询时,传入一个字符串传参数,且进行判断时,会报 There is no getter ...

  5. Android activity_main.xml删除边缘距离,充满屏幕

    删除android:paddingBottom.android:paddingLeft.android:paddingRight和android:paddingTop四个属性

  6. eclipse 切换svn账号

    1. 查看你的Eclipse中使用的是什么SVN Interface,位置在          windows > preference > Team > SVN 2. 如果是用的J ...

  7. cf158B(水题)

    题意:1辆出租车可以坐4人,已知k组人每组ki(ki<=4)人去坐车,要求同组人坐同一辆车,求最少需多少辆车.. 4人组的单独算,1人组和3人组一起,如1多余再将1和2匹配即可.... 代码如下 ...

  8. php 条件查询和多条件查询

    条件循环 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  9. 一个可能有用的封闭PGSQL操作的PYTHON函数

    URL: http://www.linuxyw.com/517.html 一般操作: import psycopg2 连接数据库 conn = psycopg2.connect(database=db ...

  10. hdu 1728:逃离迷宫(DFS,剪枝)

    逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...