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>

解决方案 »

  1.   


    全部是针对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,依次类推。
      

  2.   

    楼上的我看过的,out参数如果不是游标,我这里没有问题,但是如果是游标才会出现绑定不了的情况,还有我的事c#,和java还是有些不同的,不好意思不能给你分了
    继续坐等!!!!