• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Java and Sybase nested stored procedures

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I have nested Sybase stored procedures, the main procedure calls a helper stored proc.
The main procedure returns 2 result sets before calling the helper store proc and helper store proc returns 1 resultset. After the helper store proc is called, the main store proc returns 2 more resultset. When I run it using SQL client tool the main procedure(and it's helper) execute well and returns rows.

I need to call this store proc in a java code and display all the resultset in screen. I am using Statement:execute(<exec sp> to execute the store proc and then statement.getResultSet() to get each resultset. The loop is controlled by statement.getMoreResults() .

It displays the first 2 resultsets from main Store Proc. Then the control goes to helper store proc. It executes the helper store proc and displays the resultset from helper. But then it stops there and doesnot
come back to main store proc to execute the remaining resultset.

What I suspect is that, the statement object is getting overlaid when the call goes to helper proc. May be that Statement object maintains an internal list for Resultset and that list is over-written when helper proc is executed.

Any idea as to how to code to handle multiple nested resultset ?

~ RNS.



My Sybase stored procedure code looks like -
=======================================================================
create procedure main_proc
as

select getdate()
select @@servername

exec proc2

select myCol1, myCol2, myCol3
from mytable
select db_name()

go

===========================================================================
Sybase Code for proc2

create procedure proc2
as
begin
select @@version
end
go

GRANT EXECUTE...
EXEC sp_procxmode 'dbo.proc2,'unchained'
go
====================================================================

Code snippet :-
--------------------
do {
int iit=0;
rs=stmt.getResultSet();
if ( rs != null ) {
ResultSetMetaData rsd = rs.getMetaData();
int nocols = rsd.getColumnCount();
for (int i=1; i<=nocols; i++)
{
System.out.println(rsd.getColumnName(i)));
}
while (rs.next())
{
for (int i=1; i<=nocols; i++)
{
System.out.println(rs.getString(rsd.getColumnName(i));
}
}
}
} while (stmt.getMoreResults());
 
author & internet detective
Posts: 42165
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rabindra,
You can call stmt.getMoreResults() to advance to the next resultset and then stmt.getResultSet() to get a reference to the next resultset.
 
Rabindra Saha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code snippet :-
------------------------
do {
int iit=0;
rs=stmt.getResultSet();
if ( rs != null ) {
ResultSetMetaData rsd = rs.getMetaData();
int nocols = rsd.getColumnCount();
for (int i=1; i<=nocols; i++)
{
System.out.println(rsd.getColumnName(i)));
}
while (rs.next())
{
for (int i=1; i<=nocols; i++)
{
System.out.println(rs.getString(rsd.getColumnName(i));
}
}
}
} while (stmt.getMoreResults());
-------------------------------------------------------
What is happening is that when the call goes to helper proc, the helper proc is executed properly and displayed the result, but it is not coming back to main proc to execute its remaining resultset.
May be the internal list of resultset maintain by statement object is override by the helper proc resultset and that's why it is not processing remaining resultsets of main proc.

Thanks
RNS
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic