3 Replies - 9912 Views - Last Post: 06 July 2008 - 09:00 PM Rate Topic: -----

#1 shadowBean  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 14-June 08

rs.getString when value is null

Posted 06 July 2008 - 08:13 PM


SELECT  volume  FROM table1 WHERE date = CURDATE() AND user = ?;
.
.
.
array[0] = new String(rs.getString("volume").getBytes("utf8"), "UTF-8");
.
.



I get error message java.lang.NullPointerException

and if I use


SELECT  IFNULL(volume,'0')  FROM table1 WHERE date = CURDATE() AND user = ?;




I get javax.servlet.ServletException: java.sql.SQLException: Column 'volume' not found.

How do I get a value from database table when the value is NULL ?

Thanks,

Is This A Good Question/Topic? 0
  • +

Replies To: rs.getString when value is null

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: rs.getString when value is null

Posted 06 July 2008 - 08:22 PM

View PostshadowBean, on 6 Jul, 2008 - 08:13 PM, said:


SELECT  volume  FROM table1 WHERE date = CURDATE() AND user = ?;
.
.
.
array[0] = new String(rs.getString("volume").getBytes("utf8"), "UTF-8");
.
.



Just tested it... seems that the String constructor does not accept a null String as argument.
May be it should but it does not
So I guess you'll have to do:

String str = rs.getString("volume");
if(str == null) 
   array[0] = null;  // or "" if you wish
else
   array[0] = new String(str.getBytes("utf8"), "UTF-8");


Was This Post Helpful? 0
  • +
  • -

#3 shadowBean  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 14-June 08

Re: rs.getString when value is null

Posted 06 July 2008 - 08:49 PM

WOW! that was really fast.
Thanks , I'll try that.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: rs.getString when value is null

Posted 06 July 2008 - 09:00 PM

View PostshadowBean, on 6 Jul, 2008 - 08:49 PM, said:

WOW! that was really fast.

I was on line, was quite easy to test
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1