my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes Get a char out of a db 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 "Get a char out of a db" Watch "Get a char out of a db" New topic

Get a char out of a db

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
I have a value stored in an oracle db of type
I have tried everything in the world to read it into a char variable but I cannot get it to work.
I have tried...
How do I do it?
Paulo Salgado
Ranch Hand

Joined: Jan 18, 2002
Posts: 98
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...
[ November 07, 2002: Message edited by: Paulo Salgado ]
I agree. Here's the link:
subject: Get a char out of a db
It's not a secret anymore!