当前位置: 技术问答>java相关
存储过程的错误在哪里?
来源: 互联网 发布时间:2015-09-06
本文导语: 现在问题是我调用存储过程,打印的结果是 one= two=null three=999999 four=100000 可是我要返回的应该是 one=1 two=999999 three=100000 four=olivertest 我哪里出错了,第一个返回的是存储过程的返回值,请问我错在哪里了,请大家帮助,一定...
现在问题是我调用存储过程,打印的结果是
one=
two=null
three=999999
four=100000
可是我要返回的应该是
one=1
two=999999
three=100000
four=olivertest
我哪里出错了,第一个返回的是存储过程的返回值,请问我错在哪里了,请大家帮助,一定送分.
程序代码如下:
....
try{
CallableStatement cstmt = con.prepareCall("?={call loginodbc.Sp_GetFeeByTicketID(?,?,?,?,?)}");
cstmt.registerOutParameter(1,java.sql.Types.VARCHAR);
cstmt.setString(2,"oliver");
cstmt.setString(3,"test");
cstmt.registerOutParameter(4,java.sql.Types.VARCHAR);
cstmt.registerOutParameter(5,java.sql.Types.VARCHAR);
cstmt.registerOutParameter(6,java.sql.Types.VARCHAR);
cstmt.executeUpdate();
System.out.println("one="+cstmt.getString(1)+"n");
System.out.println("two="+cstmt.getString(4)+"n");
System.out.println("three="+cstmt.getString(5)+"n");
System.out.println("four="+cstmt.getString(6));
}catch(Exception e){
System.out.println(e);
}
存储过程代码如下:
ALTER Proc Sp_GetFeeByTicketID
@MobileNumber char(11) = null,
@MsgContent varchar(160) = null,
@OrderID varchar(10) OutPut,
@TotalFee VarChar(10) OutPut,
@Comment VarChar(50) OutPut
AS
Set @OrderID = '999999'
Set @TotalFee = '100000'
Set @Comment = @MsgContent + @MobileNumber
Return 1
GO
one=
two=null
three=999999
four=100000
可是我要返回的应该是
one=1
two=999999
three=100000
four=olivertest
我哪里出错了,第一个返回的是存储过程的返回值,请问我错在哪里了,请大家帮助,一定送分.
程序代码如下:
....
try{
CallableStatement cstmt = con.prepareCall("?={call loginodbc.Sp_GetFeeByTicketID(?,?,?,?,?)}");
cstmt.registerOutParameter(1,java.sql.Types.VARCHAR);
cstmt.setString(2,"oliver");
cstmt.setString(3,"test");
cstmt.registerOutParameter(4,java.sql.Types.VARCHAR);
cstmt.registerOutParameter(5,java.sql.Types.VARCHAR);
cstmt.registerOutParameter(6,java.sql.Types.VARCHAR);
cstmt.executeUpdate();
System.out.println("one="+cstmt.getString(1)+"n");
System.out.println("two="+cstmt.getString(4)+"n");
System.out.println("three="+cstmt.getString(5)+"n");
System.out.println("four="+cstmt.getString(6));
}catch(Exception e){
System.out.println(e);
}
存储过程代码如下:
ALTER Proc Sp_GetFeeByTicketID
@MobileNumber char(11) = null,
@MsgContent varchar(160) = null,
@OrderID varchar(10) OutPut,
@TotalFee VarChar(10) OutPut,
@Comment VarChar(50) OutPut
AS
Set @OrderID = '999999'
Set @TotalFee = '100000'
Set @Comment = @MsgContent + @MobileNumber
Return 1
GO
|
建议单步调试,凭你的代码片段很难诊断出错误!