wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
Similar Threads
How to access return value from stored procedure thru JDBC interface
Problem retrieving output from stored procedured
help in creating procedure
Retrieiving OUT parameters & return value from a Sybase Stored Procedure
Simple queries or Stored Procedures??