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, t开发者_StackOverflow社区hen 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
精彩评论