This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get a char out of a db

 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a value stored in an oracle db of type
CHAR(1)
I have tried everything in the world to read it into a char variable but I cannot get it to work.
I have tried...
demo.setAllCitiesServed((char)rs.getObject("ALL_CITIES_SERVED_FLG"));
demo.setAllCitiesServed((char)rs.getBytes("ALL_CITIES_SERVED_FLG"));
demo.setAllCitiesServed((char)rs.getString("ALL_CITIES_SERVED_FLG"));
demo.setAllCitiesServed(rs.getBytes("ALL_CITIES_SERVED_FLG"));
How do I do it?
 
Paulo Salgado
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anthony,
just like Larry Jones replied before, use String.

This handles the String and null values as well. However it does not handle empty String's. I know DB2 will return a String with blanks instead of an empty String for CHAR colums, if they are not null. However, I don't know how your DB handles that. You may want to try it first and add another if statement in case it's necessary.
Beware of other getXxx() methods to retrieve character data. For instance, getBytes() will get the byte values of a CHAR column into an array of bytes, but it WILL NOT do any character conversion for you. You most likely will end up with wrong (non-converted) characters...
Regards.
[ November 07, 2002: Message edited by: Paulo Salgado ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic