469,268 Members | 962 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

convert null into to null string

I have a sql resultset called columns. When I convert an integer
column to string that is a NULL it converts to zero. How can I get it
to convert to null??

String x;
x = Integer.toString(columns.getInt("Integercolumnname "));

if x is null it will be converted to '0'. I want it converted to
null.
Jul 17 '05 #1
4 32397
If I understand you correctly it should be something like this:

String x = (null == columns.getInt("Integercolumnname"))
? null
: Integer.toString(columns.getInt("Integercolumnname "))
;

"DiggidyMack69" <Di***********@hotmail.com> wrote in message
news:c8*************************@posting.google.co m...
I have a sql resultset called columns. When I convert an integer
column to string that is a NULL it converts to zero. How can I get it
to convert to null??

String x;
x = Integer.toString(columns.getInt("Integercolumnname "));

if x is null it will be converted to '0'. I want it converted to
null.

Jul 17 '05 #2
It looks like all your can do is test for null by using the
getObject("columnName") method. According to the JavaDoc, this will
return null if there isn't a value in the field. I'm surprised there
isn't an isNull("columnName") method.

-Nathan

Di***********@hotmail.com (DiggidyMack69) wrote in message news:<c8*************************@posting.google.c om>...
I have a sql resultset called columns. When I convert an integer
column to string that is a NULL it converts to zero. How can I get it
to convert to null??

String x;
x = Integer.toString(columns.getInt("Integercolumnname "));

if x is null it will be converted to '0'. I want it converted to
null.

Jul 17 '05 #3
There is allways the wasNull() method call. If the converted value returns 0
this can allways be cahnged to some different value if the value 'wasNull'.
But unfortunatelly this value has to be fetched first :)

Rein

"Nathan Zumwalt" <na*****@hotmail.com> wrote in message
news:52**************************@posting.google.c om...
It looks like all your can do is test for null by using the
getObject("columnName") method. According to the JavaDoc, this will
return null if there isn't a value in the field. I'm surprised there
isn't an isNull("columnName") method.

-Nathan

Di***********@hotmail.com (DiggidyMack69) wrote in message

news:<c8*************************@posting.google.c om>...
I have a sql resultset called columns. When I convert an integer
column to string that is a NULL it converts to zero. How can I get it
to convert to null??

String x;
x = Integer.toString(columns.getInt("Integercolumnname "));

if x is null it will be converted to '0'. I want it converted to
null.

Jul 17 '05 #4
"Reinaerde" <re*******@yahoo.com> wrote in message news:<3f***********************@news.xs4all.nl>...
If I understand you correctly it should be something like this:

String x = (null == columns.getInt("Integercolumnname"))
? null
: Integer.toString(columns.getInt("Integercolumnname "))
;

"DiggidyMack69" <Di***********@hotmail.com> wrote in message
news:c8*************************@posting.google.co m...
I have a sql resultset called columns. When I convert an integer
column to string that is a NULL it converts to zero. How can I get it
to convert to null??

String x;
x = Integer.toString(columns.getInt("Integercolumnname "));

if x is null it will be converted to '0'. I want it converted to
null.


Unfortunately if I do that the servlet won't compile. it tells me that
basically an int cannot be null. im going to play with the getObject
though.
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by BlueDragon | last post: by
1 post views Thread by Swarup | last post: by
6 posts views Thread by JKop | last post: by
5 posts views Thread by moondaddy | last post: by
3 posts views Thread by bussiere maillist | last post: by
2 posts views Thread by Joah Senegal | last post: by
8 posts views Thread by =?Utf-8?B?UmljYXJkbyBRdWludGFuaWxsYQ==?= | last post: by
3 posts views Thread by mamul | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.