• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
  • Frits Walraven
  • fred rosenberger
  • salvin francis

How to handle error from CallableStatement??

Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jsp that will add users for an application to the database. If the user tries to add a new user that is already in the database, the stored procedure (Sybase) is printing out text saying that 'This user already exists with the following information.' and then prints the resultset of a select query on the table for the given username. How do I handle that from Java? I know of CallableStatement.registerOutParameter(), but can this method handle this return? If I register the out parameter as a String (is this possible), could I save all of this text into a String so I can display it to the user? Please help me handle this appropriately. I really want to display this String from the database, as I feel it is a more meaningful message than just telling the user 'This person is already registered as a user.' Thanks for any and all help you are able to provide!
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can return multiple parameters from the stored procedure, set them as OUT parameters.
CallableStatemnt cst....
cst.registerOutParameter(1, java.sql.Types.VARCHAR);//userid
cst.registerOutParameter(2, java.sql.Types.VARCHAR);//username
cst.setString(3, "new username");
userid = cst.getString(1);
username = cst.getString(2);
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic