无法从mybatis执行的oracle过程中接收参数

无法从mybatis执行的oracle过程中接收参数

本文介绍了无法从mybatis执行的oracle过程中接收参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Spring 3.0.5开发java应用程序,并使用mybatis-spring使用数据库Oracle。

I develop java application using Spring 3.0.5 and I work with database Oracle using mybatis-spring.

我有一个mybatis接口:

I've an interface for mybatis:

public interface SubscriberMapper {
    Subscriber getSubscriberByMsisdn(String msisdn);

    void insertSubscriber(Subscriber subscriber);

    void updateSubscriber(Subscriber subscriber);

    void canCustomerSubscribe(@Param("msisdn") String msisdn,
                         @Param("responseCode") Integer responseCode);

}

canCustomerSubscribe的mybatis xml内容:

mybatis xml content for canCustomerSubscribe:

<parameterMap id="canCustomerSubscribeParams" type="map">
    <parameter property="msisdn" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
    <parameter property="responseCode" jdbcType="NUMERIC" javaType="java.lang.Integer" mode="OUT"/>
</parameterMap>
<select id="canCustomerSubscribe" parameterMap="canCustomerSubscribeParams" statementType="CALLABLE">
    CALL wallet.pkg_wallet_validation.can_customer_subscribe(#{msisdn}, #{responseCode})
</select>

和要执行的代码:

public void subscribe(String msisdn) throws InvalidArgumentException {
    Integer responseCode = 0;
    subscriberMapper.canCustomerSubscribe(msisdn, responseCode);
    System.out.println("msisdn: " + msisdn + ", responseCode: " + responseCode);
}

当我使用无效的msisdn执行subscribe方法时,我不会从程序中获得实际价值。在数据库中执行此过程会返回reponseValue = 1001,但在Java代码中我收到0.我打开调试日志记录为stout for mybatis,输出为:

When I execute "subscribe" method with invalid "msisdn", I do not receive real out value from procedure. Execution of this procedure in the database returns reponseValue = 1001, but in Java code I receive 0. I turned on debug logging to stout for mybatis and output is:

2011-10-19 10:32:46,732 DEBUG [main] (Slf4jImpl.java:28) ooo Connection Opened
2011-10-19 10:32:46,909 DEBUG [main] (Slf4jImpl.java:28) ==>  Executing: CALL wallet.pkg_wallet_validation.can_customer_subscribe(?, ?)
2011-10-19 10:32:46,911 DEBUG [main] (Slf4jImpl.java:28) ==> Parameters: 509999999(String), 0(Integer)
msisdn: 509999999, responseCode: 0

当我更改subscribe方法responseCode = null时,我收到并收到错误:

When I change in "subscribe" method responseCode = null, I receive and error:

org.springframework.jdbc.UncategorizedSQLException: Error setting null parameter.  Most JDBC drivers require that the JdbcType must be specified for all nullable parameters. Cause: java.sql.SQLException: Invalid column type
; uncategorized SQLException for SQL []; SQL state [null]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type


推荐答案

我找到了解决方案。在canCustomerSubscribe方法中,Map必须是user而不是两个参数。

I found solution. Map must be user instead of two parameter in canCustomerSubscribe method.

 void canCustomerSubscribe(Map<String,Object> params);

mybatis xml内容:

mybatis xml content:

<select id="canCustomerSubscribe" parameterType="java.util.HashMap" statementType="CALLABLE">
    CALL wallet.pkg_wallet_validation.can_customer_subscribe(
    #{msisdn, jdbcType=VARCHAR, javaType=java.lang.String, mode=IN},
    #{responseCode,jdbcType=NUMERIC, javaType=java.lang.Integer, mode=OUT})
</select>

(我需要在参数属性之间添加逗号)

(I need to add the commas between arguments attributes)

从订阅服务方法调用它:

calling it from subscribe service method:

public void subscribe(String msisdn) throws InvalidArgumentException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("msisdn", msisdn);
    params.put("responseCode", null);
    subscriberMapper.canCustomerSubscribe(params);
    System.out.println(params.get("responseCode"));
}

这篇关于无法从mybatis执行的oracle过程中接收参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 09:38