how do I test if a certain field in a resultset has a null value.
I tried the following:
if (r.getString("field") == null) {
}
but it doesn't seem to work. I stll get a NullPointerException.
Thanks
Henk
"Henk Roos" <henkr@.vippayroll.co.za> schrieb im Newsbeitrag
news:%23DY6yt6fEHA.3548@.TK2MSFTNGP09.phx.gbl...
> Hi All,
> how do I test if a certain field in a resultset has a null value.
> I tried the following:
> if (r.getString("field") == null) {
> }
> but it doesn't seem to work. I stll get a NullPointerException.
The proper idiom that JDBC prescribes is this:
String val = r.getString("field");
if ( r.wasNull() ) {
// treat NULL
}
else {
// treat other values
}
Regards
robert
|||Henk Roos wrote:
> Hi All,
> how do I test if a certain field in a resultset has a null value.
> I tried the following:
> if (r.getString("field") == null) {
> }
> but it doesn't seem to work. I stll get a NullPointerException.
Show more of the code, and show the line where you get the
exception. That code (you show) should work.
Joe Weinstein at BEA
> Thanks
> Henk
>
|||If you are getting the NullPointerException in the first line (the first tiime you call the ResultSet, you should try this
String field=null;
if (r.next()){
field=r.getString("field");
}
In other way( you are moving in the ResultSet) try this:
if (!r.wasNull())
field=r.getString("field");
Good Luck

Camaliro
Quote:
Hi All,
how do I test if a certain field in a resultset has a null value.
I tried the following:
if (r.getString("field") == null) {
}
but it doesn't seem to work. I stll get a NullPointerException.
Thanks
Henk
No comments:
Post a Comment