![](/img/trans.png)
[英]MyBatis and Sybase Stored Procedure - ResultSet with unnamed columns
[英]MyBatis: Sybase stored procedure returns zero rows
我已經從此處復制了文本: 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.
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
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
您能否檢查出問題所在,該怎么辦以確保可以調用這種存儲過程?
我想為以上帖子修改一個錯字。
通常結果應該是:
DEBUG PreparedStatement - ==> Executing: {call tempdb..testSP ?}
DEBUG PreparedStatement - ==> Parameters: mydata(String)
DEBUG ResultSet - <== Columns: result1, result2
DEBUG ResultSet - <== Row: 1, mydata
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.