aspose file tools*
The moose likes JDBC and the fly likes retrieving value from SQL Server 2000 stored procedure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "retrieving value from SQL Server 2000 stored procedure" Watch "retrieving value from SQL Server 2000 stored procedure" New topic
Author

retrieving value from SQL Server 2000 stored procedure

as chhipa
Greenhorn

Joined: Sep 04, 2006
Posts: 26
Hi every body
I want to execute an query in stored procedure and after some calculation I want to retrieve some value which is specified by variable i in the follwing stored procedure.

CREATE procedure spTemp
@i as int OUTPUT
as
--select * from customer
......
......
......
select @i=3;
GO


Follwing is the code snippet for retrieving values from stored procedure
CallableStatement cs=conn.prepareCall("{call temp1(?)}");
cs.registerOutParameter(1,Types.INTEGER);
cs.execute();
int j=cs.getInt(1);
System.out.println("i="+j);


If I do not execute the query I get the correct value of i that is 3 but if I execute the query I get 0 as the value.
Can any body suggest why is it so and how can I execute the query and retrieve the values at the same time

Thank You.
Dan Howard
Ranch Hand

Joined: Feb 22, 2004
Posts: 47
You need to use

and then look at the result set for the return value.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: retrieving value from SQL Server 2000 stored procedure