MyBatis:Sybase存储过程返回零行

时间:2010-11-05 07:22:36

标签: java orm ibatis mybatis

我从这里复制了文字: http://code.google.com/p/mybatis/issues/detail?id=164,但我们遇到了同样的问题。

MyBatis 3.0.1版

我使用MyBatis 3作为java应用程序和sybase数据库之间的OR映射。 用于从数据库查询数据的sql是一个存储过程,对于简单的过程是可以的,但是如果在存储过程中声明并使用了内部变量,它似乎无法正常工作,查询结果为null,而在那里也不例外。

下面的

是示例代码,我也附加为附件。 的JavaBean:


    public class Test {

    private String input1;
    private String input2;

    public String getInput1() {
        return input1;
    }

    public void setInput1(String input1) {
        this.input1 = input1;
    }

    public String getInput2() {
        return input2;
    }

    public void setInput2(String input2) {
        this.input2 = input2;
    }
    }

SQLMAP:


    <mapper namespace="cargoStatus_shipment">
    <resultMap id="testMap"     type="com.icil.esolution.cargoStatus.AS.model.Test">
    <result column="result1" jdbcType="VARCHAR" property="input1" />
    <result column="result2" jdbcType="VARCHAR" property="input2" />
    </resultMap>

    <select id="getValidData" statementType="CALLABLE"     resultMap="testMap"     parameterType="String">
     {call tempdb..testSP #{in}}
    </select> 

    </mapper>

存储过程:


    use tempdb
    go
    drop proc testSP
    go
    create proc testSP
      @in varchar(10)

    as
     declare @var char(3)
     select @var="XXX"
     select result1= '1', result2=@in
    go
    grant exec on testSP  to public
    go

Java代码:


public class TestSP {


  private static SqlSessionFactory createSqlMapper() throws IOException {
        String resource = "resources/sqlMapConfig.xml";
        Reader reader = Resources.getResourceAsReader(resource);
        return new SqlSessionFactoryBuilder().build(reader,"development");
  }


  public static void main(String[] args) {

    SqlSession session=null;
    try {
          session = createSqlMapper().openSession(ExecutorType.SIMPLE, true); //autocommit = true

    } catch (Exception e) {
       e.printStackTrace();
       System.out.println("Error in open Session. Cause: " + e);
       System.exit(1);
    }


    List result = (List) session.selectList("getValidData", "mydata"); 

    System.out.println("Result = "+result);
    System.out.println(result.get(2).getInput2());

  }

}

通常结果应为:

DEBUG PreparedStatement - ==>  Executing: {call tempdb..testSP ?} 
DEBUG PreparedStatement - ==> Parameters: mydata(String)
DEBUG ResultSet - 

but actually, there is no result get, neither exceptions:

DEBUG PreparedStatement - ==>  Executing: {call tempdb..testSP ?} 
DEBUG PreparedStatement - ==> Parameters: mydata(String)

after counter test, if i remove the inner variable @var from the sp, then it will be ok.

DEBUG PreparedStatement - ==>  Executing: {call tempdb..testSP ?} 
DEBUG PreparedStatement - ==> Parameters: mydata(String)

你能检查一下是什么问题,我该怎么做才能确保我可以调用这种存储过程?

1 个答案:

答案 0 :(得分:1)

我想修改上述帖子的一个拼写错误。

通常结果应为:
DEBUG PreparedStatement - ==> Executing: {call tempdb..testSP ?}
DEBUG PreparedStatement - ==> Parameters: mydata(String)
DEBUG ResultSet - <== Columns: result1, result2
DEBUG ResultSet - <== Row: 1, mydata