• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1166
  • Last Modified:

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

0
Tolomir
Asked:
Tolomir
  • 3
  • 3
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
TolomirAdministratorAuthor Commented:
The code snipped did it.
0
 
CEHJCommented:
:-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now