This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

null results

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad that could help.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not sure i understand sachin's suggestion. no reference to nvl on the java site.
??
jb
 
Michal Harezlak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin is refering to the SQL syntax.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!