Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle error from CallableStatement??

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • 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!
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic