permaculture playing cards
The moose likes JDBC and Relational Databases and the fly likes How to handle error from CallableStatement?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to handle error from CallableStatement??" Watch "How to handle error from CallableStatement??" New topic

How to handle error from CallableStatement??

verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
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!
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
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);
Don't get me started about those stupid light bulbs.
subject: How to handle error from CallableStatement??
It's not a secret anymore!