How can i know the String object is created or is null

M

mahesh

HI alll

in my code i want to check that the sql query return null value
and if the query return null value the i hav to use

stmt.setXXX(1,Types.some oracle type)
else
i hav to set other value for that column using
stmt.setXXX(1,****)
to find null values i'm using
String st=rst.getInt(1).toString();
but if it returns null then it set the st=null
and it trhows null pointer exception
is there any way to achieve this
 
B

Bart Cremers

HI alll

in my code i want to check that the sql query return null value
and if the query return null value the i hav to use

stmt.setXXX(1,Types.some oracle type)
else
i hav to set other value for that column using
stmt.setXXX(1,****)
to find null values i'm using
String st=rst.getInt(1).toString();
but if it returns null then it set the st=null
and it trhows null pointer exception
is there any way to achieve this

If you want to receive a String from a resultset it's better to use
rst.getString(index). So:

String st = rst.getString(1);

if (st == null) {
doSomething();
} else {
doSomethingElse();
}


Regards,

Bart
 
P

Patricia Shanahan

mahesh said:
HI alll

in my code i want to check that the sql query return null value
and if the query return null value the i hav to use

stmt.setXXX(1,Types.some oracle type)
else
i hav to set other value for that column using
stmt.setXXX(1,****)
to find null values i'm using
String st=rst.getInt(1).toString();
but if it returns null then it set the st=null
and it trhows null pointer exception
is there any way to achieve this

If that line itself throws the exception, you are not even getting to
the point of calling toString.

Is it possible that rst is null? If so, you need to test for that first.

As others have indicated, test for null by == comparison.

Patricia
 
M

mahesh

Bart said:
If you want to receive a String from a resultset it's better to use
rst.getString(index). So:

String st = rst.getString(1);

if (st == null) {
doSomething();
} else {
doSomethingElse();
}


Regards,

Bart




thank u
 
M

mahesh

Bart said:
If you want to receive a String from a resultset it's better to use
rst.getString(index). So:

String st = rst.getString(1);

if (st == null) {
doSomething();
} else {
doSomethingElse();
}


Regards,

Bart




thank u
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top