Hello, I have a stored proc in SQL Server 2005, which looks like the following (simplified)
CREATE PROCEDURE FOO
@PARAMS
AS
BEGIN
-- STEP 1: POPULATE tmp_table
DECLARE @tmp_table TABLE (...)
INSERT INTO @tmp_table
SELECT * FROM BAR
-- STEP 2: USE @tmp_table FOR FINAL SELECT
SELECT abc, pqr
FROM BAZ JOIN @tmp_table
ON some_criteria
END
When I run this proc from SQL Server Management Studio, things work fine. However, when I call the same proc from a Java program, using something like:
cs = connection.prepareCall("exec proc ?,");
cs.setParam(...);
rs = cs.getResultSet(); // BOOM - Null!
while(rs.next()) {...} // NPE!
I fail to understand why the first result set returned is NULL. Can someone explain this to me?
As a workaround, if I check cs.getMoreResults() and if true, try another getResultSet() - THIS time it returns the proper result set.
Any pointers please? (I'm using JTDS drivers, if it matters)
Thanks, Raj