求助,JAVA调用存储过程的问题??
我要在JAVA里调用SQLSERVER的存储过程
存储过程比较复杂,有多个输入参数和多个回传参数。
存储过程定义如下:
CREATE PROC PROC_K3CUser_I @Number VARCHAR(255),@Name VARCHAR(255),@Msg VARCHAR(255) OUTPUT,@ItemID1 INT OUTPUT,@ItemID2 INT OUTPUT
AS
BEGIN
..........
调用:
try{
Connection con = DBTools.getConnection();//得到Connection
CallableStatement proc = con.prepareCall( "{ call PROC_K3CUser_I(?, ?, ?, ?, ? ) } ");
proc.setString(1, "ss0001 ");
proc.setString(2, "测试 ");
proc.registerOutParameter(3, Types.NVARCHAR);
proc.registerOutParameter(4, Types.INTEGER);
proc.registerOutParameter(5, Types.INTEGER);
proc.execute();
String out1 = proc.getString(1);
int out2 = proc.getInt(2);
int out3 = proc.getInt(3);
}
catch (
SQLException e)
{
// ....}
}
直接这样定义CallableStatement的参数都不对,怎么定义都不对;更别说调用了
只能求助大家了,先谢过了。。。。
------解决方案--------------------String out1 = proc.getString(1);
int out2 = proc.getInt(2);
int out3 = proc.getInt(3);
------------------------------按顺序来
String out1 = proc.getString(3);
int out2 = proc.getInt(4);
int out3 = proc.getInt(5);
------解决方案--------------------楼上正解