我有一个应该返回代码的存储过程。PFB 样本 SP。
USE [TEST]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[test_sp]
-- Add the parameters for the stored procedure here
@id int,
@name varchar(25),
@return_code int OUTPUT
AS
BEGIN
select @return_code=1
return @return_code
END
调用此 SP 的 Java 类:
public int callSP() {
Connection con = getConnection();
ResultSet rs = null;
CallableStatement ct = null;
int returnCode = -1;
try {
ct = con.prepareCall("{call test_sp (?,?,?)}");
ct.setInt(1, 1);
ct.setString(2, "divya");
ct.registerOutParameter(3, java.sql.Types.INTEGER);
ct.executeQuery();
returnCode = ct.getInt(3);
if (returnCode == 0) {
System.out.println("Success");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
database.close(rs, ct, con);
}
return returnCode;
}
运行此程序时出现异常。异常发生在ct.executeQuery();
并说,
com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
谁能帮我吗?