日期:2014-05-20  浏览次数:20794 次

myBatis执行带输出参数的存储过程问题
下面是存储过程需要的参数,存储过程在mysql里测试执行是可以得到想要的结果的
SQL code


    IN i_tableName VARCHAR(1024),
    IN i_searchFields VARCHAR(1024),
    IN i_pageIndex VARCHAR(10),    
    IN i_pageSize VARCHAR(10),
    IN i_whereCondition VARCHAR(1024),
    IN i_orderString VARCHAR(200),
    OUT o_totalRows INT,
    OUT o_totalPages INT
....


这个是测试sql代码
SQL code

CALL commonPage('core_user', '*', '1', '1', 'where 1=1', '', @rowsCount, @pagesCount);


 在使用mybatis执行这个存储过程,我先贴一下我的代码
XML code

<parameterMap id="pageParameter" type="Map">
        <parameter property="i_tableName" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
        <parameter property="i_searchFields" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
        <parameter property="i_pageIndex" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
        <parameter property="i_pageSize" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
        <parameter property="i_whereCondition" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
        <parameter property="i_orderString" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
        <parameter property="o_totalRows" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT"/>
        <parameter property="o_totalPages" jdbcType="VARCHAR" javaType="java.lang.String" mode="OUT"/>
    </parameterMap>



XML code

 <select id="getUserPageList" parameterMap= "pageView.pageParameter" resultType="User">
         
        <![CDATA[
                { CALL commonPage(?, ?, ?, ?, ?, ?, ?, ?)}
        ]]>
    </select> 


使用时传的参数
Java code

                  Map<String, String> mp= new Map<String, String>();
                  mp.put("i_tableName", i_tableName);
        mp.put("i_searchFields", i_searchFields);
        mp.put("i_pageIndex", i_pageIndex);
        mp.put("i_pageSize", i_pageSize);
        mp.put("i_whereCondition", i_whereCondition);
        mp.put("i_orderString", i_orderString);
        mp.put("o_totalRows", "0");
        mp.put("o_totalPages", "0");
                  
  ....
public List<User> getUserPageList(PageParameter map)
    {
            return getSqlSessionTemplate().selectList("com.permissions.entity.User.getUserPageList", map.getMp());
    }


运行时出现异常:

java.sql.SQLException: No value specified for parameter 7
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1737)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1685)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:806)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)
......