How to convert boolean values (true,false,undefined) to a string

Hello,

I need a solution to convert a boolean value to string.
Easy job if there where not those undefined (null) values.

So I need at best a one liner to handle this problem:

boolean value: true -> 'true'
boolean Value: undefined (null),false -> 'false'

Tolomir

LVL 27
TolomirAdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Are you working in a db? A primitive boolean can only have 2 states
0
cr4ck3rj4ckCommented:
Hi there,

http://www.javadb.com/convert-boolean-to-string

Hope that helps,
CJ
0
TolomirAdministratorAuthor Commented:
Hello,

yes I'm working with a postgreSQL DB and I want to export values with a java tool to an oracle DB (ETL process)

PostgreSQL got that "nice" a boolean can be undefined feature.... causing me problems.

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

TolomirAdministratorAuthor Commented:
Right now I'm trying something like this:

oracle_tmp.f25string = row1.f25boolean <> NULL ? row1.f25boolean.toString(): 'false';

0
CEHJCommented:
Try calling the following with resultSet.getObject(booleanFieldIndex)


    public static String boolToString(Object o) {
        return o == null? "null" : ((Boolean)o).toString();
    }
 
//even the following could do it ;-)
 
    public static String boolToString(Object o) {
        return "" + o;
    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TolomirAdministratorAuthor Commented:
The code snipped did it.
0
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.