mysql存储过程可以直接返回结果集,同时可以有out参数
例如:
存储过程:
view plaincopy to clipboardprint?
CREATE PROCEDURE `test`
(IN _login VARCHAR(32),
IN _psw VARCHAR(32),
OUT _ret INTEGER(10),
OUT _id INTEGER(10),
OUT _name VARCHAR(32),
OUT _email VARCHAR(32),
OUT _phone VARCHAR(20),
OUT _active INTEGER(11)) //同时返回多个结果集合
BEGIN
DECLARE CONTINUE HANDLER FOR NOT FOUND set _ret =-1;
set _ret = 0 ;
select id,name,email,phone,active
into _id,_name,_email,_phone,_active
from test
where tx_account.`loginname`=_login and tx_account.`password`=MD5(_psw) and active=1;
---------返回结果集-----
if _ret = 0 then
select a.id as id ,a.name as name,a.priority as priority
from test b left join test1 a on b.role=a.id
where b.account=_id;
end if;
END;
直接返回结果集
ibatis文件
<parameterMap id="testParameterMap" class="params">
<parameter property="loginname" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
<parameter property="password" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
<parameter property="ret" jdbcType="INTEGER" javaType="java.lang.Integer" mode="OUT"/>
<parameter property="id" jdbcType="INTEGER" javaType="java.lang.Integer" mode="OUT"/>
<parameter property="name" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT"/>
<parameter property="phone" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT"/>
<parameter property="email" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT"/>
<parameter property="active" jdbcType="INTEGER" javaType="java.lang.Integer" mode="OUT"/>
</parameterMap>
<procedure id="test" parameterMap="testMap" resultMap="AccountRoleResultMap">
{call test(?,?,?,?,?,?,?,?)}
</procedure>
dao 的实现
定义一个传参的map params ,
HashMap<String,Object> params = new HashMap<String,Object>();
//把需要的参数放到map中
params.put("id",account.getId());
params.put("ret",null);
params.put("loginname", null);
params.put("name", null);
params.put("email", null);
params.put("phone",null);
params.put("active", null);
//定义一个list
List list=null;
list= (List)(getSqlMapClientTemplate().queryForList("test",params));
//上面这样操作就可以获得存储过程返回的结果集。
Object var;
var = params.get("ret"); //从map 中获得制定的输出参数的值。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yangzl0123/archive/2009/10/29/4743721.aspx
分享到:
相关推荐
ibatis调用oracle存储过程分页
ibatis调用oracle存储过程
ibatis调存储过程返回游标,资料整理
Ibatis调用Oracle存储过程,返回自定义的类型。
使用J2EE+Spring+Ibatis+JDBC 调用存储过程,并返回结果集的配置详细。 供学习参考。
Ibatis中调用其它的SQL语句很容易,那么如何在Ibatis中调用存储过程呢?
C#中iBatis连接mySQL使用的DLL
IBATIS调用存储过程
iBatis调用存储过程
ibatis调用存储过程使用示例,处理带参数及无参数类型的存储过程,是一个不错的例子。
NULL 博文链接:https://pzh244658240.iteye.com/blog/1423681
用ibatis调用存储过程的介绍,使用java语言进行开发
基于SQLserver 数据库的IBatis中存储过程应用实例
ibatis调用存储过程.txt [removed] var share_info = {}; [removed]
Spring + Ibatis 与mysql集群集成
ibatismysql.jar ibatismysql.jar
ibatis +mysql 实例 :是一个web项目 (简单的增删改查)
NULL 博文链接:https://jun1986.iteye.com/blog/1290064
初学ibatis 自己实现的一个简单的ibatis查询mysql的文档,内容不是很多,但是对学习来说很有帮助,关于配置文件及整个项目工程的结构一目了然,这是在eclipse下实现的