Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC empty field

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
I am setting a member boolean in a class file depending on whether a particular resultSet column is empty. (cartStatus = false if it's empty and cartStatus = true if it has string content.)

I find that if I try getting the field content that I get a null pointer exception later which I guess means that java doesn't get "" when it reads the field:

[red]if (rst.getString("order")=="") cartStatus = false;[/red]

(throws nullPointer)

and doing:

[red]if (rst.getString("order")==null) cartStatus = false;[/red]

would be an invalid type comparison.

so instead I did the whole thing another way which was to get the column value as an object (getObject() instead of getString()), compare it to null then read it later as a string:

in class declaration:
[red]public boolean cartObj;[/red]

one method:
[red]public void getCartStatus()
{
if ((cartObj=rst.getObject())==null) cartStatus = false;
else cartStatus = true;
}[/red]

then in another method:
[red]public void getCartOutput()
{
String cartString = cartObj.toString();
}[/red]

This works but it seems round about. Is there a more direct way to check whether a string field is zero length?
[sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
 
sorry
public boolean cartObj;
should have been
public Object cartObj; [sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top