I have one saved proc written on MS Sql server, which has a cursor and a temporary table in it and returns the result of one select query at the end.
I am trying to call it from java with the following code snippet
final Connection conn = getConnection();
final CallableStatement statement = conn.prepareCall("{call dbo.storedProcName (?) }");
statement.setString(1, "value1,value2");
final ResultSet rs = statement.executeQuery();
while (rs.next()) {
}
When I execute this code in java, I get the result set as null. The stored proc returns values when I run it on the sql server console with the same parameters that I pass from java code.
Any idea what causes this problem here?
I am using sqljdbc4.jar, Java 7 and SQL Server 2008 R2.
Error stack
com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:392)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:281)
Saved Raw Format
create procedure [dbo].[storedProcName](
@inpurparam varchar(4000)
)
as
begin
select some_values into
//declare some_variables
declare @table2 table(col1 varchar(10), col2 varchar(10))
declare cursor for select * from
open cursor
fetch next from cursor into some_params
while @@fetch_status = 0
begin
//some processing
//insert into table2 based on some logic
fetch next ..
end
close cursor
deallocate cursor
drop table
select col1, col2 from @table2
order by col1
end to go
source
share