0

I want to use the ResultSet in java program to get data from Stored procedure's cursor. Is that possible with SQL Server?

My code:

CREATE PROCEDURE dbo.SampleProcedure AS 
DECLARE @FirstName varchar(64)
DECLARE @LastName varchar(64)
DECLARE c1 CURSOR READ_ONLY
FOR
SELECT FIRST_NAME, LAST_NAME
FROM EMPLOYEE

OPEN c1

FETCH NEXT FROM c1
INTO @FirstName, @LastName


CLOSE c1
DEALLOCATE c1

When I use EXEC SampleProcedure, I just got the output as "Command(s) completed successfully" and the Resultset shows null in java program. So what to change in my code so that my ResultSet retrieves data?

I want to know how to prepare ResultSet in the SQL Server code so that I can retrieve the same in java program.

1

1 Answer 1

1

SQL Server stored procedures can return record-sets from a query, a CURSOR would not be required (unlike in Oracle). The query below is all that's needed to get a recordset:

CREATE PROCEDURE dbo.SampleProcedure 
AS 
SELECT FIRST_NAME, LAST_NAME
FROM EMPLOYEE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.