By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,738 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,738 IT Pros & Developers. It's quick & easy.

Numeric Nulls

P: n/a
Here is a code snippet I have.

Float.valueOf(rs.getString(((rsmd.getColumnName(x+ 1).toString()!=null
&& !rsmd.getColumnName(x+1).toString().equals(""))?rs md.getColumnName(x+1).toString():"0"))).floatValue ()

and the part:
rs.getString(((rsmd.getColumnName(x+1).toString()! =null &&
!rsmd.getColumnName(x+1).toString().equals(""))?rs md.getColumnName(x+1).toString():"0"))

where it is testing the field for null values isn't working. It is
always getting thru even thow I KNOW the data is null.

The Problem I have is that no matter how hard I try, if the field is
NUMERIC in Oracle and the value is NULL, it passes all these tests:

rsmd.getColumnName(x+1).toString()!=null
!rsmd.getColumnName(x+1).equals("")
!rsmd.getColumnName(x+1).equals(null)
!rsmd.getColumnName(x+1).toString().equals("")
rsmd.getColumnName(x+1).toString().length()>0

I am trying to do a Float.valueOf() and because the field is null i am
getting this error.

Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at java.lang.FloatingDecimal.readJavaFormatString(Flo atingDecimal.java:980)
at java.lang.Float.valueOf(Float.java:205)

I know the field is null but it still passes all those tests.
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ho**********@hotmail.com (Rob H) wrote in
news:75**************************@posting.google.c om:
Here is a code snippet I have.

Float.valueOf(rs.getString(((rsmd.getColumnName(x+ 1).toString()!=null
&&
!rsmd.getColumnName(x+1).toString().equals(""))?rs md.getColumnName(x+1).t
oString():"0"))).floatValue()

and the part:
rs.getString(((rsmd.getColumnName(x+1).toString()! =null &&
!rsmd.getColumnName(x+1).toString().equals(""))?rs md.getColumnName(x+1).t
oString():"0"))

where it is testing the field for null values isn't working. It is
always getting thru even thow I KNOW the data is null.

The Problem I have is that no matter how hard I try, if the field is
NUMERIC in Oracle and the value is NULL, it passes all these tests:

rsmd.getColumnName(x+1).toString()!=null
!rsmd.getColumnName(x+1).equals("")
!rsmd.getColumnName(x+1).equals(null)
!rsmd.getColumnName(x+1).toString().equals("")
rsmd.getColumnName(x+1).toString().length()>0

I am trying to do a Float.valueOf() and because the field is null i am
getting this error.

Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at
java.lang.FloatingDecimal.readJavaFormatString(Flo atingDecimal.java:
980) at java.lang.Float.valueOf(Float.java:205)

I know the field is null but it still passes all those tests.


Perhaps instead of
rsmd.getColumnName(x+1).toString()!=null
you could check
rsmd.getColumnName(x+1)!=null

toString() generally does not return null.
By the way, it is usually clearer to write
x?y:z
instead of
!x?z:y

--
Ian Shef
These are my personal opinions and not those of my employer.
Jul 17 '05 #2

P: n/a
Ian Shef wrote:
ho**********@hotmail.com (Rob H) wrote in
news:75**************************@posting.google.c om:

Here is a code snippet I have.

Float.valueOf(rs.getString(((rsmd.getColumnName( x+1).toString()!=null
&&
!rsmd.getColumnName(x+1).toString().equals(""))? rsmd.getColumnName(x+1).t
oString():"0"))).floatValue()

and the part:
rs.getString(((rsmd.getColumnName(x+1).toString( )!=null &&
!rsmd.getColumnName(x+1).toString().equals(""))? rsmd.getColumnName(x+1).t
oString():"0"))

where it is testing the field for null values isn't working. It is
always getting thru even thow I KNOW the data is null.

The Problem I have is that no matter how hard I try, if the field is
NUMERIC in Oracle and the value is NULL, it passes all these tests:

rsmd.getColumnName(x+1).toString()!=null
!rsmd.getColumnName(x+1).equals("")
!rsmd.getColumnName(x+1).equals(null)
!rsmd.getColumnName(x+1).toString().equals("")
rsmd.getColumnName(x+1).toString().length()>0

I am trying to do a Float.valueOf() and because the field is null i am
getting this error.

Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at
java.lang.FloatingDecimal.readJavaFormatString(Flo atingDecimal.java:
980) at java.lang.Float.valueOf(Float.java:205)

I know the field is null but it still passes all those tests.

Perhaps instead of
rsmd.getColumnName(x+1).toString()!=null
you could check
rsmd.getColumnName(x+1)!=null

toString() generally does not return null.


Not only that, if rsmd.getColumnName(x+1) == null, then
rsmd.getcolumnName(x+1).toString() will throw a NullPointerException
because you're trying to execute the toString() method on a null pointer...

Derek
Jul 17 '05 #3

P: n/a
Rob H wrote:
Here is a code snippet I have.

Float.valueOf(rs.getString(((rsmd.getColumnName(x+ 1).toString()!=null
&& !rsmd.getColumnName(x+1).toString().equals(""))?rs md.getColumnName(x+1).toString():"0"))).floatValue ()
That's pretty ugly. You can extract some of those into local variables
to make things a little more readable.

In any case:
The Problem I have is that no matter how hard I try, if the field is
NUMERIC in Oracle and the value is NULL, it passes all these tests:

rsmd.getColumnName(x+1).toString()!=null
!rsmd.getColumnName(x+1).equals("")
!rsmd.getColumnName(x+1).equals(null)
!rsmd.getColumnName(x+1).toString().equals("")
rsmd.getColumnName(x+1).toString().length()>0

I am trying to do a Float.valueOf() and because the field is null i am
getting this error.


You're doing a Float.valueOf on a database column name? Do you normally
name your database columns with floating point numbers?

Perhaps you really meant to actually call rs.getString(...) and then
compare that to null (or call rs.wasNull just afterward, for a more
universal way to check for null values).

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 17 '05 #4

P: n/a
Liz

"Derek Chen-Becker" <db*****@cpicorp.com> wrote in message
news:c9**********@cpimail.cpicorp.com...
Ian Shef wrote:
ho**********@hotmail.com (Rob H) wrote in
news:75**************************@posting.google.c om:

Here is a code snippet I have.

Float.valueOf(rs.getString(((rsmd.getColumnName( x+1).toString()!=null
&&
!rsmd.getColumnName(x+1).toString().equals(""))? rsmd.getColumnName(x+1).t
oString():"0"))).floatValue()

and the part:
rs.getString(((rsmd.getColumnName(x+1).toString( )!=null &&

!rsmd.getColumnName(x+1).toString().equals(""))? rsmd.getColumnName(x+1).t
oString():"0"))

where it is testing the field for null values isn't working. It is
always getting thru even thow I KNOW the data is null.

The Problem I have is that no matter how hard I try, if the field is
NUMERIC in Oracle and the value is NULL, it passes all these tests:

rsmd.getColumnName(x+1).toString()!=null
!rsmd.getColumnName(x+1).equals("")
!rsmd.getColumnName(x+1).equals(null)
!rsmd.getColumnName(x+1).toString().equals("")
rsmd.getColumnName(x+1).toString().length()>0

I am trying to do a Float.valueOf() and because the field is null i am
getting this error.

Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at
java.lang.FloatingDecimal.readJavaFormatString(Flo atingDecimal.java: 980) at java.lang.Float.valueOf(Float.java:205)

I know the field is null but it still passes all those tests.

Perhaps instead of
rsmd.getColumnName(x+1).toString()!=null
you could check
rsmd.getColumnName(x+1)!=null

toString() generally does not return null.


Not only that, if rsmd.getColumnName(x+1) == null, then
rsmd.getcolumnName(x+1).toString() will throw a NullPointerException
because you're trying to execute the toString() method on a null

pointer...
Derek


What Derek says makes it look like the claim of passing the tests
isn't totally true unless throwing an exception counts as passing.
Jul 17 '05 #5

P: n/a
Liz wrote:
"Derek Chen-Becker" <db*****@cpicorp.com> wrote in message
news:c9**********@cpimail.cpicorp.com...
Ian Shef wrote:
ho**********@hotmail.com (Rob H) wrote in
news:75**************************@posting.googl e.com:

Here is a code snippet I have.

Float.valueOf(rs.getString(((rsmd.getColumnNam e(x+1).toString()!=null
&&

!rsmd.getColumnName(x+1).toString().equals("")) ?rsmd.getColumnName(x+1).t

oString():"0"))).floatValue()

and the part:
rs.getString(((rsmd.getColumnName(x+1).toStrin g()!=null &&

!rsmd.getColumnName(x+1).toString().equals("")) ?rsmd.getColumnName(x+1).t

oString():"0"))

where it is testing the field for null values isn't working. It is
always getting thru even thow I KNOW the data is null.

The Problem I have is that no matter how hard I try, if the field is
NUMERIC in Oracle and the value is NULL, it passes all these tests:

rsmd.getColumnName(x+1).toString()!=null
!rsmd.getColumnName(x+1).equals("")
!rsmd.getColumnName(x+1).equals(null)
!rsmd.getColumnName(x+1).toString().equals(" ")
rsmd.getColumnName(x+1).toString().length()> 0

I am trying to do a Float.valueOf() and because the field is null i am
getting this error.

Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at

java.lang.FloatingDecimal.readJavaFormatString(Flo atingDecimal.java:
980) at java.lang.Float.valueOf(Float.java:205)

I know the field is null but it still passes all those tests.

Perhaps instead of
rsmd.getColumnName(x+1).toString()!=null
you could check
rsmd.getColumnName(x+1)!=null

toString() generally does not return null.


Not only that, if rsmd.getColumnName(x+1) == null, then
rsmd.getcolumnName(x+1).toString() will throw a NullPointerException
because you're trying to execute the toString() method on a null


pointer...
Derek

What Derek says makes it look like the claim of passing the tests
isn't totally true unless throwing an exception counts as passing.


Good catch, I should have been paying more attention to the original
poster. The first method will throw a NullPointerException and the rest
of them will never be executed...

Derek
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.