I am trying to call a stored procedure from java and I'm having some issues getting the call to go through correctly. I've looked up numerous examples, but they don't match the syntax of the stored procedure I'm trying to call.
STORED PROCEDURE CODE
------------------------
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[getMgr]
@UserID as varchar(5),
@ModeType as char(1)
AS
BEGIN
SELECT usermgrid from AllEmployees WHERE (ModeType = @ModeType AND UserID =
@UserID)
END
JAVA CODE
----------------------------
connection = getConnection();
cs = connection.prepareCall("{call lvhsp_GetManager(?, ?) }");
cs.setString(0, someUserID);
cs.setString(1, "0");
ResultSet resultSet = cs.executeQuery();
I've tried calling the stored procedure a number of different ways but I continue to get errors.
When I call it like this, I get a:
com.microsoft.sqlserver.jdbc.SQLServerException: The index 0 is out of range.
Which I assume is because that is not the correct way to pass a parameter.
I've also tried calling it with the parameter names (UserID, ModeType) with and without the @, but that doesn't work.
What am I missing?