I had to deal with a lot of null values coming back from a database. I may
have been reinventing the wheel but I wrote a little DBUtil class that I
used to sanitize the returned data. I wrote a get for each type of data and
did a try catch. If the data came back not null I simply returned it, if it
came back null it threw an exception and I returned back a default value in
the catch clause.
For text:
/** returns the row and column equivalent from the DBResults or empty
string if null or out of bounds*/
public String getDataP(int r, int c){
try{
if ((((String[])queryResults.elementAt(r))[c]).equalsIgnoreCase("null"))
return "";
return(((String[])queryResults.elementAt(r))[c]);
}catch(Exception e){return "";}
}
For numbers:
/** returns the row and column equivalent from the DBResults or string 0
if null or out of bounds*/
public String getDataN(int r, int c){
try{
if ((((String[])queryResults.elementAt(r))[c]).equalsIgnoreCase("null"))
return "0";
return(((String[])queryResults.elementAt(r))[c]);
}catch(Exception e){return "0";}
}
For time:
/** returns the row and column equivalent from the DBResults or string
00:00:00 if null or out of bounds*/
public String getDataT(int r, int c){
try{
if ((((String[])queryResults.elementAt(r))[c]).equalsIgnoreCase("null"))
return "00:00:00";
return(((String[])queryResults.elementAt(r))[c]);
}catch(Exception e){return "00:00:00";}
}
Doug
----- Original Message -----
From: "Propes, Barry L " <[EMAIL PROTECTED]>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Friday, June 22, 2007 1:11 PM
Subject: RE: Null
that doesn't sound right....are you sure you're pulling back a value from a
column that's a string?
-----Original Message-----
From: Mohammed Zabin [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 21, 2007 6:02 AM
To: Tomcat Users List
Subject: Re: Null
I tried it the other way, if( rs.getString("field") == null ) but the
compiler plames that null can't be compared to string....
On 6/21/07, Tim Funk <[EMAIL PROTECTED]> wrote:
if (null == rs.getString("col_foo")) {
out.println("<td> </td>");
} else {
// Evil since this doesn't escape the xml - for edutainment only
out.println("<td>" + rs.getString("col_foo") + "</td>");
}
-Tim
Mohammed Zabin wrote:
> Hi All
>
> Anyone knows how to deal with null values in JDBC ResultSet??
>
> I am trying to render a table in jsp page that read its value from the
> database, sometimes, the database returns null values, and so, the whole
> table couldn't be rendered. Is there any way to deal with null values.
>
> Thanks
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]