• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the value of a boolean OUT parameter in stored procedure

 
liang gu
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get the value of OUT parameters. I basically do the following
String command = "{ call myStoredProc(?,?,?)}";
CallableStatement cstmt = conn.prepareCall (command);
cstmt.setBytes(1, ids);
cstmt.setString(2,someValue);
//Problem here on **
cstmt.registerOutParameter(3, Types.**);
cstmt.execute();
rt = cstmt.getBoolean(3);
The third parameter is an OUT parameter with boolean type, however, in java.sql.Type class, there is no static field for boolean. How can I register the OUT parameter type to be boolean?
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure the best you can do is map a true/false value to an int ( 0 and 1 ) or to some character representation 'T','F','true', or 'false'. Most databases don't have boolean datatypes, so it is not supported in java.sql.types.
Jamie
 
liang gu
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jamie:
Thanks for your reply. However, I am not convinced by you. The CallableStatement interface has getBoolean() and setBoolean() method, it will be inconsistent if CallableStatement can not set boolean type in method registerOutParameter()
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by liang gu:
Jamie:
Thanks for your reply. However, I am not convinced by you. The CallableStatement interface has getBoolean() and setBoolean() method, it will be inconsistent if CallableStatement can not set boolean type in method registerOutParameter()

you shouldn't be convinced, cause I didn't answer your question correctly! I guess I should read instead of skimming! Anyways, did you try java.sql.Types.BIT?
Jamie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic