ibatis.net调用存储过程怎么接收游标值?
这个问题困扰我2天了一直解决不了,现在上来看看有没有别人知道ibatis的配置文件内容给出来:
<parameterMaps>
<parameterMap id="ParCflowWatch" class="EtyGuestWatch">
<parameter property="PTimeFlag" column="PTIMEFLAG" dbType ="Number" direction="Input"/>
<parameter property="PCflowTimeStart" column="PCFLOWTIMESTART" dbType ="Varchar2" direction="Input"/>
<parameter property="PCflowTimeEnd" column="PCFLOWTIMEEND" dbType ="Varchar2" direction="Input"/>
<parameter property="PCflowType" column="PCFLOWTYPE" dbType ="Varchar2" direction="Input"/>
<parameter property="stationID" column="LSTCFLOWDATA" dbType ="ORACLECURSOR" direction="Output"/>
</parameterMap>
</parameterMaps><resultMap id="SelectProCflow" class="EtyGuestWatch">
<result property="cflowTypeID" column="CFLOW_TYPE_ID" />
<result property="cflowTypeName" column="TYPE_NAME" />
<result property="cflowCount" column="CFLOW_COUNT" />
<result property="cflowTimeStart" column="CFLOW_TIME_START" />
<result property="cflowTimeEnd" column="CFLOW_TIME_END" />
</resultMap>
<procedure id="SelectHisTrnCflow" parameterMap="ParCflowWatch" resultMap="SelectProCflow">
LC_TRN_CFLOW.GET_LC_TRN_CFLOW
</procedure>
这个问题困扰我2天了一直解决不了,现在上来看看有没有别人知道ibatis的配置文件内容给出来:
<parameterMaps>
<parameterMap id="ParCflowWatch" class="EtyGuestWatch">
<parameter property="PTimeFlag" column="PTIMEFLAG" dbType ="Number" direction="Input"/>
<parameter property="PCflowTimeStart" column="PCFLOWTIMESTART" dbType ="Varchar2" direction="Input"/>
<parameter property="PCflowTimeEnd" column="PCFLOWTIMEEND" dbType ="Varchar2" direction="Input"/>
<parameter property="PCflowType" column="PCFLOWTYPE" dbType ="Varchar2" direction="Input"/>
<parameter property="stationID" column="LSTCFLOWDATA" dbType ="ORACLECURSOR" direction="Output"/>
</parameterMap>
</parameterMaps><resultMap id="SelectProCflow" class="EtyGuestWatch">
<result property="cflowTypeID" column="CFLOW_TYPE_ID" />
<result property="cflowTypeName" column="TYPE_NAME" />
<result property="cflowCount" column="CFLOW_COUNT" />
<result property="cflowTimeStart" column="CFLOW_TIME_START" />
<result property="cflowTimeEnd" column="CFLOW_TIME_END" />
</resultMap>
<procedure id="SelectHisTrnCflow" parameterMap="ParCflowWatch" resultMap="SelectProCflow">
LC_TRN_CFLOW.GET_LC_TRN_CFLOW
</procedure>
解决方案 »
- el表达式?
- post方式提交Action获得的是空值,跪求解决方案啊!
- 求一个jsp实现bt和迅雷下载的源码
- 这个分页时奇怪的问题是什么原因啊
- +++++++++++逼上梁山++++求用QQ远程来帮我JSP(SQL注入式漏洞问题)解决后,要多少分给多少分.+++++++++++++++++++++++++++++++++++++++++++
- 狂晕,简单语句出错?
- 为什么javabean的值在jsp里是null
- 能不能把inputStream 读到byte[]中
- 现有一循环问题。请帮忙看看
- 高分求解:我这样的配置如何使用连接池?
- excel内存溢出
- 一个servlet即要保存数据,又要实现发邮件功能,怎么写?
全部是针对Microsoft SQL Server 2000的Stored Procedure的例子:
参照《iBATIS in Action》书写:
1. max_in_example
Stored Procedure:
CREATE PROCEDURE [dbo].[max_in_example]
@a INTEGER = 0 OUTPUT,
@b INTEGER = 0 OUTPUT,
@c INTEGER = 0 OUTPUT
AS
BEGIN
IF (@a > @b)
SET @c = @a
ELSE
SET @c = @b
RETURN @c
END
GO
SqlMap:
<parameterMap id="pm_in_example" class="java.util.Map">
<parameter property="c" javaType="int" jdbcType="INTEGER"
mode="OUT" />
<parameter property="a" javaType="int" jdbcType="INTEGER" />
<parameter property="b" javaType="int" jdbcType="INTEGER" />
</parameterMap>
<procedure id="in_example" parameterMap="pm_in_example"
resultClass="int">
{ ? = call max_in_example(?, ?) }
</procedure>
Java Code:
publicstatic Integer getMax_in_example(int a, int b) throws SQLException {
Map<String, Integer> m = new HashMap<String, Integer>(2);
m.put("a", new Integer(a));
m.put("b", new Integer(b));
m.put("c", new Integer(0));
//执行存储过程in_example
sqlMapper.queryForObject("in_example", m);
return m.get("c");
}
2. swap
Stored Procedure:
CREATE PROCEDURE [dbo].[swap]
@a INTEGER OUTPUT,
@b INTEGER OUTPUT
AS
BEGIN
DECLARE @temp INTEGER
SET @temp = @a
SET @a = @b
SET @b = @temp
END
GO
SqlMap:
<parameterMap id="swapProcedureMap" class="java.util.Map">
<parameter property="a" javaType="int" jdbcType="INTEGER"
mode="INOUT" />
<parameter property="b" javaType="int" jdbcType="INTEGER"
mode="INOUT" />
</parameterMap>
<procedure id="swapProcedure" parameterMap="swapProcedureMap">
{ call swap(?, ?) }
</procedure>
Java Code:
publicstatic Map swap(int a, int b) throws SQLException {
Map<String, Integer> m = new HashMap<String, Integer>(2);
m.put("a", new Integer(a));
m.put("b", new Integer(b));
//执行存储过程swap
sqlMapper.queryForObject("swapProcedure", m);
return m;
}
3. maximum
Stored Procedure:
CREATE PROCEDURE [dbo].[maximum]
@a INT OUTPUT,
@b INT OUTPUT,
@c INT OUTPUT
AS
BEGIN
IF(@a > @b)
SET @c = @a
IF(@b >= @a)
SET @c = @b
END
GO
SqlMap:
<parameterMap id="maxOutProcedureMap" class="java.util.Map">
<parameter property="a" mode="IN" />
<parameter property="b" mode="IN" />
<parameter property="c" jdbcType="INTEGER" mode="OUT" />
</parameterMap>
<procedure id="maxOutProcedure"parameterMap="maxOutProcedureMap">
{ call maximum (?, ?, ?) }
</procedure>
Java Code:
publicstatic Integer maximum(int a, int b) throws SQLException {
Map<String, Integer> m = new HashMap<String, Integer>(2);
m.put("a", new Integer(a));
m.put("b", new Integer(b));
m.put("c", new Integer(0));
//执行存储过程maximum
sqlMapper.queryForObject("maxOutProcedure", m);
return m.get("c");
}
以上的Java Code类方法都是写在相应的ProcedureDAOImpl类中,可以通过ProcedureDAOImpl类调用相应得方法和传入对应参数来与数据库存储过程交互。
注意:在SqlMap.xml文件中<parameterMap>中参数的顺序跟<Procedure>中”?”的顺序一致。
如:a, b, c; ? = procedurename(?, ?) 则,第一个问号表示a,依次类推。
继续坐等!!!!