• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling a stored procedure

 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all:

I have a stored procedure that returns a bigint not a resultset.

cs = connection.prepareCall(sql);
cs.execute();

How can I get the returned value?

thanks
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figuered it out.

Thank you
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hanna,

Can you post your solution? It helps fellow ranchers that have the same question.

Regards, Jan
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jan Cumps:
Hanna,

Can you post your solution? It helps fellow ranchers that have the same question.

Regards, Jan




Here is my solution:

Connection connection = null;
String sql = "{ ? = call getNextEntityId }";
Long id = null;
CallableStatement cs = null;
try
{
connection = session.connection();
cs = connection.prepareCall(sql);
cs.registerOutParameter(1, Types.BIGINT);
cs.execute();
id = cs.getLong(1);
logger.info("generate(): Id generated successfuly: " + id);

return(id);
}

The key is to register the OUT parameters before you execute the stored procedure. In the above case, the stored proc. returns one value, so I registered one value. Then, you get the registered values in the same order they are registerd and with the same type as they are registerd using cs.getXX()
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
Regards, Jan
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic