wood burning stoves 2.0*
The moose likes JDBC 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to handle error from CallableStatement??" Watch "How to handle error from CallableStatement??" New topic
Author

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.
eg.
CallableStatemnt cst....
cst.registerOutParameter(1, java.sql.Types.VARCHAR);//userid
cst.registerOutParameter(2, java.sql.Types.VARCHAR);//username
cst.setString(3, "new username");
cst.execute();
userid = cst.getString(1);
username = cst.getString(2);
 
Consider Paul's rocket mass heater.
 
subject: How to handle error from CallableStatement??
 
Similar Threads
Reading specific words from search engines
Build a boolean expression from a String : CriteriaFind(String criteria)
How to pull data from database using JSP?
Java Script Addition in for loop
xml & jsp