http://www.apachebookstore.com/confluence/oss/display/IBATIS/Oracle+REF+CURSOR+Solutions
The resultType is only used if the procedure returns a result set (not
a result set parameter, just a result set from invoking the
procedure).
So, change someBean to include the two output parameters, delete the
resultType, and things should be good to go.
Jeff Butler
when i configured like this, the output value is not updated to the
JavaBean.
I use the example you posted before
sqlMap config:
<update id="adder2" parameterType="spTest.Parameter"
statementType="CALLABLE">
{call tempdb..adder(
#{addend1,jdbcType=INTEGER,mode=IN},
#{addend2,jdbcType=INTEGER,mode=IN},
#{sum,jdbcType=INTEGER,mode=OUT}
)}
</update>
JavaBean:
public class Parameter {
private Integer addend1;
private Integer addend2;
private Integer sum;
public Integer getAddend1() {
return addend1;
}
public void setAddend1(Integer addend1) {
this.addend1 = addend1;
}
public Integer getAddend2() {
return addend2;
}
public void setAddend2(Integer addend2) {
this.addend2 = addend2;
}
public Integer getSum() {
return sum;
}
public void setSum(Integer sum) {
this.sum = sum;
}
}
public interface SPMapper {
Object adder(Parameter parameter);
void adder2(Parameter parameter);
Name getName(Integer id);
List<Name> getNames(Map<String, Object> parms);
}
testing code:
SqlSession sqlSession = null;
try {
sqlSession = createSqlMapper().openSession();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
// initialize
Parameter parameter = new Parameter();
parameter.setAddend1(2);
parameter.setAddend2(3);
SPMapper spMapper = sqlSession.getMapper(SPMapper.class);
spMapper.adder2(parameter);
System.out.println("summary is: "+parameter.getSum());
// initialize
parameter = new Parameter();
parameter.setAddend1(2);
parameter.setAddend2(3);
spMapper.adder2(parameter);
} finally {
sqlSession.close();
}
and I use sybase database, the sp is:
create procedure adder
@addend1 int,
@addend2 int,
@theSum int output
as
select @theSum = @addend1 + @addend2
is it the sybase cause the problem or something wrong with my config?
--
View this message in context: http://mybatis-user.963551.n3.nabble.com/How-to-get-output-from-stored-procedure-to-ibatis-class-tp1785718p2056325.html
Sent from the mybatis-user mailing list archive at Nabble.com.
SP in db:
create procedure adder
@addend1 int,
@addend2 int,
@theSum int output
as
select @theSum = @addend1 + @addend2
the SqlMap config:
<update id="adder2" parameterType="spTest.Parameter" statementType="CALLABLE">
{call tempdb..adder(
#{addend1,jdbcType=INTEGER,mode=IN},
#{addend2,jdbcType=INTEGER,mode=IN},
#{result,jdbcType=INTEGER,mode=OUT}
)}
</update>
And the testing code:
...
Parameter parameter = new Parameter();
parameter.setAddend1(1);
parameter.setAddend2(3);
parameter.setResult(0);
sqlSession.update("adder2",parameter);
System.out.println("Addend1 is: "+parameter.getAddend1());
System.out.println("Addend2 is: "+parameter.getAddend2());
System.out.println("Result is: "+parameter.getResult());
The testing result is:
Addend1 is: 1
Addend2 is: 3
Result is:
0
When I change to sqlSession.selectOne("adder2",parameter);
The result is:
Addend1 is: 1
Addend2 is: 3
Result is: 4
create procedure adder
@addend1 int,
@addend2 int,
@theSum int output
as
select @theSum = @addend1 + @addend2
You can retrieve output parameters with update - the SP examples do
just that. You cannot retrieve a result set with update, but I don't
think that's what you really want.
Your first example looks right to me, don't know why it doesn't work.
I think it would be good at this point to turn on MyBatis logging to
see if you can spot the problem.
Jeff Butler
Jeff Butler
The bottom line is this - don't use the batch executer if you need to
retrieve output parameters. The workaround is simple - use the default
executer. It works perfectly.
Jeff Butler
--
Sent from my mobile device