iBatis for Java is a good way of abstracting away the SQL statements from the business logic; it relies on XML files which contain all SQL statements and it is pretty simple to access a database. Because accessing DB2 from Java is pretty new for me I had some troubles finding a sample to setup a “insert” statement which returns the last inserted ID.
With PHP I’d use my_insert_id(), but how does it work with Java and DB2? Unfortunately all samples I could find where either based on Oracle or on the Microsoft SQL Server…. no luck.
So here is the XML required for an INSERT statement with iBatis on DB2:
<insert id=”insertTABLE” parameterclass=”TABLE”>
INSERT INTO TABLE
(…)
VALUES
(#…#)
<selectkey resultclass=”int” keyproperty=”id”>
SELECT IDENTITY_VAL_LOCAL() as ID FROM SYSIBM.SYSDUMMY1
</selectkey>
</insert>
After that the insert statement can be used like follows:
TABLE_BEAN table_bean = new table_bean();
table_bean.setXXX(…);
mySqlMapClient.insert(“insertTABLE”, table_bean);
// now table_bean.getId() returns the correct id
From now on iBatis works like a charm and the object value is automatically updated… nice!
相关推荐
ibatis的insert方法的返回值。 介绍了mybaits如何处理返回值的问题。
spring和ibatis配置与模板
ibatis配置文件模板.包括(SqlMap.properties和SqlMapConfig.xml以及跟javabean的映射文件)
IBatis codesmith模板,简单 实用
通过Ibatis3xml文件配置+Mysql实现数据批量插入,原先在网上找很多,都是关于批量更新,批量插入的很少,而且其写法又完全不同,所以自己研究了一下。可供参考。另外插入时如出现内容报错,请参照my.cnf修改书库配置...
NULL 博文链接:https://yhq1212.iteye.com/blog/1772214
参照例子写的iBATIS模板
可生自动批量生成IBATIS代码,本人在多个项目中使用
虽然很简单但是自己写的,包括生成代码和xml文件两个文件,保证可以通过!绝对超值!
参照nhibernate模板文件和ibatis.net教程相关示例制作的codesmith模板文件,C#环境
ibatis学习 ibatis总结 ibatis ibatis ibatis
里面融合了spring+struts+ibatis用到的配置文件模板,这样我们就可以不用到处去找了。。
压缩包里包括Mygeneration_1309_2008100代码生成软件,自带IBatisObject模板,可根据数据库字段生成实体类和SQLMapping映射文件。
注:附带模板,使用手册,环境配置等。 1)、数据库类型选择:目前支持Oracle和Mysql两种数据库语句的生成,默认是Oracle。 2)、要生成建表语句, a)、请在“数据库定义Excel文件路径”中选择对应的文件, ...
闲着没事写了个demo项目,ibatis和mybatis差不多,可自行调配前端框架
亲手做的一个spring ibatis整合,刚刚接触ibatis,二话不说,ibatis环境先搭建好。
ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料
ibatis 增删改查(DB2版本),用其他数据库的话,直接把配置文件改一下就可以了。WEBROOT下面有建表sql语句
使用的struts2_spring_ibatis框架,根据模板文件导出Excel
ibatis demo,ibatis例子,ibatis示例