aspose file tools*
The moose likes JDBC and the fly likes null results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "null results" Watch "null results" New topic
Author

null results

Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
strange things are happening in my program when i get a 'null' value for a particular column/row in my resultset.
on the one hand the value seems to be a string with the 4 letters 'n', 'u', 'l' and 'l'. on the other hand, if i try to 'trim' it, it gives me a fatal exception.
what's going on?
Michal Harezlak
Ranch Hand

Joined: Jul 06, 2000
Posts: 185
Jay,
They are not really of a String class they are just null. When you print them out you will see null, but there is no way to do any method calls on them.

Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
so how do i query them? basically, i don't want to print anything if the row is null. right now, it's throwing an exception when i try to compare it as a string.
thanks
jay
Michal Harezlak
Ranch Hand

Joined: Jul 06, 2000
Posts: 185
It's happening because there is nothing (no object) to compare it with: null. You might want to check for null if (whatever!=null).
Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
the last one did it. thanks michael!
i never realized it is so simple to check for null values.
i LOVE this board.
jay
Michal Harezlak
Ranch Hand

Joined: Jul 06, 2000
Posts: 185
Glad that could help.
sachin sachdeva
Greenhorn

Joined: Mar 13, 2001
Posts: 14
whenever u are writing ur query write nvl method in that and replace null with any other value like space also.
Otherwise it will give you null pointer execption
Example
select nvl(empno,'') from emp
Michal Harezlak
Ranch Hand

Joined: Jul 06, 2000
Posts: 185
Unfortunately that will not always work, for numeric values it will raise an SQLException. What's more I'm not sure if that is a part of 92 standard, is it? I have seen that approach in the PL/SQL.
Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
not sure i understand sachin's suggestion. no reference to nvl on the java site.
??
jb
Michal Harezlak
Ranch Hand

Joined: Jul 06, 2000
Posts: 185
Sachin is refering to the SQL syntax.
 
Consider Paul's rocket mass heater.
 
subject: null results