Thread: null: was is the default returned value?

null: was is the default returned value?

From
Jean-Christian Imbeault
Date:
What value does the jdbc driver return from the various getXXX()
functions when the DB return value is null?

I've been having some trouble using getObject() and getStr() on
ResultSets that contain null values for some fields.

If I do Object o = r.getObject("col") and the returned value is null I
get a nullPointeException. But for String s = r.getStr("col") I get a
value that prints out as "null" ... so if getStr() works I don't
understand why getObject() doesn't ...

Thanks,

Jc


Re: null: was is the default returned value?

From
Toby
Date:
 >What value does the jdbc driver return from the various getXXX()
functions when the DB return value is null

i think this is undefined. what you need to do is first call your getXXX()
call and then follow up with a wasNull() call.

 >But for String s = r.getStr("col") I get a value that prints out as "null"

if you tried doing the following, i think you'd see the same thing happening

    String s;

    System.out.println("s=" + s);

the printing of null isn't to do with the database, its to do with the
default behaviour of the String class, even though you have a null instance.

t


Re: null: was is the default returned value?

From
Jean-Christian Imbeault
Date:
Toby wrote:
>
> i think this is undefined. what you need to do is first call your
> getXXX() call and then follow up with a wasNull() call.

You're right. Thanks for the explanation. I didn't know about wasNull().
That fixes everything!

Jc


Re: null: was is the default returned value?

From
Sean Liu
Date:
how to remove me from the mailing list?

thanks,
sean

--- Jean-Christian Imbeault <jc@mega-bucks.co.jp>
wrote:
> Toby wrote:
> >
> > i think this is undefined. what you need to do is
> first call your
> > getXXX() call and then follow up with a wasNull()
> call.
>
> You're right. Thanks for the explanation. I didn't
> know about wasNull().
> That fixes everything!
>
> Jc
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
majordomo@postgresql.org