?
Solved

Sybase, JDBC and output values

Posted on 2005-03-09
5
Medium Priority
?
731 Views
Last Modified: 2012-06-21
Hi There,
I have a stored procedure which returns a few parameters using the output keyword, ie

declare @id1 numeric(9,0), @id2 numeric(9,0)
execute my_proc  'Mr'  ,'Peewee'  ,'Gibbons'  ,'N'  ,@id1 output ,@id2 output

The proc itself works fine as expected, ie over an isql session it runs and returns the two parameters.  My question is that how do i execute this via jdbc and get access to the two output values?

Here my java code thus far:

Connection conn = "connect string";
String insert = "declare @id1 numeric(9,0), @id2 numeric(9,0) execute my_proc  'Mr'  ,'Peewee'  ,'Gibbons'  ,'N'  ,@id1 output ,@id2 output";

Statement stmt = conn.createStatement();
boolean rc             = stmt.execute(insert);
conn.close();

can someone ammend my java code to point me in the right direction so that i know how to access the output values.

thanks in advance
pg
0
Comment
Question by:Peewee
5 Comments
 
LVL 5

Author Comment

by:Peewee
ID: 13498230
one thing i forgot to mention was that the sql itself is just inserting data and returns no resultset itself.  If i ask for a resultset i get the following error:

java.sql.SQLException: JZ0R2: No result set for this query.

These are not my procs so i dont have the option of modifying them.

pg
0
 
LVL 6

Expert Comment

by:ChrisKing
ID: 13504469
Well I am no java expert, but this is a problem that happens in other languagues too

amend you SQL to select your variables after the exec.
eg
String insert = "declare @id1 numeric(9,0), @id2 numeric(9,0) execute my_proc  'Mr'  ,'Peewee'  ,'Gibbons'  ,'N'  ,@id1 output ,@id2 output SELECT id1 = @id1, id2 = @id2";

then you will have a result set with the values, so you can ft\etch them as normal.

ChrisKing
0
 
LVL 14

Accepted Solution

by:
Jan Franek earned 200 total points
ID: 13509188
Look at CallableStatement - it should be used for calling stored procedures and you can define output parameters there.
0
 
LVL 1

Expert Comment

by:nadhuvi
ID: 13515803
For calling stored procedures writeen in any sql try to use Callablestatement and you will not get this kind of error

0
 
LVL 14

Expert Comment

by:Jan Franek
ID: 13524170
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
The following information will get you familiar with your new DV server, including the (mt) Account Center, the Plesk Control Panel, our world-renowned support department and the rest of the (mt) tools that come with your new service.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question