NullPointerException with CallableStatement.getResultSet()
Posted
by Raj
on Stack Overflow
See other posts from Stack Overflow
or by Raj
Published on 2010-06-16T03:45:12Z
Indexed on
2010/06/16
3:52 UTC
Read the original article
Hit count: 460
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
© Stack Overflow or respective owner