tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "PTS" <parsonstechni...@gmail.com>
Subject Re: Null
Date Thu, 28 Jun 2007 02:33:15 GMT
In several of the fields of the database the information is not entered 
until a later time and thus the field is null. If you look at actual data 
the value is null. When returned the data either is "null" or is not 
compatible with the data needed back. I am using the data in several areas. 
If I am expecting a String and it is null, then I want an empty string to be 
displayed. If I am expecting a number then I want a 0 if it is null. If the 
data returned is not of the type expected then I catch the exception and 
return the equivalent of no information for that data type.

As for the String[], I am pulling back an entire row from the database and 
then picking a single element from the array. In essence it allows me to 
treat the result set as a two dimensional array.

The concept that I was trying to convey to the OP was to do a try catch and 
return the desired default value of the proper type.

Doug

----- Original Message ----- 
From: "domenico di leo" <domenico.dileo@gmail.com>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Wednesday, June 27, 2007 7:08 AM
Subject: Re: Null


> If I have understand your problem is : you receive a lot of null value
> afther a query but you don't except them.
> The problem could be in your if statement .
>
> ((String[])queryResults.elementAt(r))[c]).equalsIgnoreCase("null"))
>
> you compare a String vector with a String because you have upacsted to
> String[]  the return value of queryResult.
> I think you should do something like this:
>
> String[] queryResult = new String[10]
> /* Suppose that the queryResult method yelds a vector fill with 10 String
>
> queryResult = new ((String[])queryResults.elementAt(r))[c])
>
> afther
>
> for (int i=0; i<= queryResult.lenght(); i++){
> if queryResult[i].equalsIgnoreCase("null"))
>    return null; // Why do you use "" ?
>  return queryResult[i];
> }
>
> Cheers
>
> On 25/06/07, Propes, Barry L <barry.l.propes@citi.com> wrote:
>> yeah, this seems like a good solution, too.
>>
>> -----Original Message-----
>> From: PTS [mailto:parsonstechnical@gmail.com]
>> Sent: Saturday, June 23, 2007 12:29 PM
>> To: Tomcat Users List
>> Subject: Re: Null
>>
>>
>> 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 " <barry.l.propes@citi.com>
>> 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:jotnarta@gmail.com]
>> 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 <funkman@joedog.org> wrote:
>> >
>> >
>> > if (null == rs.getString("col_foo")) {
>> >    out.println("<td>&nbsp;</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: users-unsubscribe@tomcat.apache.org
>> > For additional commands, e-mail: users-help@tomcat.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message