English 中文(简体)
MyBatis: Sybase stored procedure returns zero rows
原标题:

I have copied the text from here: http://code.google.com/p/mybatis/issues/detail?id=164, but we faced the same issue.

MyBatis version 3.0.1

I use MyBatis 3 as the OR mapping between the java application and sybase database. The sql used to query data from the database is a stored procedure, it is ok for simple procedure, but if there is inner variable declared and used in the stored procedure, it seems does not work correctly, the query result is null, while there is no exception throwing.

below is the example code, and i also attach as the attachment. 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>

stored procedure:


    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 code:


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());

  }

}

normally the result should be:

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.

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

    as
     select result1=  1 , result2=@in
    go
    grant exec on testSP  to public
    go

Could you pls check what is the problem and what shall I do to make sure I can call this kind of stored procedure?

问题回答

I woule like to revise one typo for above post.

normally the result should be:
DEBUG PreparedStatement - ==> Executing: {call tempdb..testSP ?}
DEBUG PreparedStatement - ==> Parameters: mydata(String)
DEBUG ResultSet - <== Columns: result1, result2
DEBUG ResultSet - <== Row: 1, mydata





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签