You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Brett Palmer <pl...@hotmail.com> on 2000/01/17 19:01:34 UTC

RE: NullPointerException

I agree with always checking if the ResultSet was Null (i.e. rs.wasNull()).  
This is necessary because some JDBC drivers set the return value to 0 when 
the ResultSet is NULL.  This may not be what you want.

Brett


>From: "James B. Walters" <Ja...@APEXinteractive.com>
>To: "Darko" <da...@home.com>, "Noel J. Bergman" <no...@ibm.net>
>CC: "Fornoff, Michael" <Mi...@dresdner-bank.com>, 
><gn...@gjt.org>
>Subject: RE: NullPointerException
>Date: Mon, 17 Jan 2000 10:41:04 -0600
>
>The java.sql.ResultSet.getString methods return null if the value
>in the database was null.  So you need to check for that condition
>when you use them
>
>if(RE4 == null) RE4 = "";
>
>The other get methods in java.sql.ResultSet return various things
>when they find a null, so it is best to call the wasNull() method
>immediately after using one of them.  You can call it for String's, too.
>
>if(rs.wasNull()) RE4 = "";
>
>
>
>-----Original Message-----
>From: Darko [mailto:darko55@home.com]
>Sent: Monday, January 17, 2000 10:29 AM
>To: Noel J. Bergman
>Cc: Fornoff, Michael; gnujsp@gjt.org
>Subject: NullPointerException
>
>
>Hello,
>
>I have an interesting problem.
>I am using jdk117_v1a, JSDK2.0, Apache-JServ-1.0, and my test servlet is
>working fine.
>When I try to get something from a database, if it is null, and I try to
>test
>it in my code I get NullPointerException in my jserv.log. But if there is
>something in that field in the database, it works fine. I dont know why 
>this
>is
>happening. Here is a sample code if anybody could help me.
>
>String RE4 = null;
>...connect to db and retrieve data ...
>  RE4 = rs.getString("RE4");
>int p4=0;
>String Name4 = null;
>     if(!RE4.equals(""))
>  {
>      p4 = RE4.indexOf("@");
>           Name4 = RE4.substring(0,p4);
>  }
>
>Now, if there is something in RE4, it is fine, but if there is nothing, it
>throws NullPointerException.
>COuld it be my Jserv configuration, which I doubt, or is it my code ?
>Another
>thing is null and "" the same thing, when dealing with strings ?
>
>Thanx,
>
>Darko
>
>
>
>

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com