You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Patrick Meyer <me...@gmail.com> on 2010/12/14 20:45:31 UTC

inserting missing values

What is the best way to handle missing values. For example, suppose I have
an array that I want to insert into a table, like double[] row = {1.0, 2.0,
MISSING,  4.0} where MISSING indicates a value that is missing. (I realize
this is not a valid double value). I have been using a prepared statement to
set a null value anytime I have missing data like, pstmt.setNull(i+1,
Types.DOUBLE); However, the problem is that using rs.getDouble(3) returns a
value of zero instead of null. The problem is that zero is a legitimate
double value, not a missing or null value. Is it better to inset data using
Double.NAN like pstmt.setDouble(i+1, Double.NaN);? What is the best way to
handle missing data?

Thanks

Re: inserting missing values

Posted by Patrick Meyer <me...@gmail.com>.
Aha! That's just what I needed. Thank you!

On Tue, Dec 14, 2010 at 3:05 PM, Peter Ondruška <pe...@gmail.com>wrote:

> You need to check using wasNull method whether the value is null. See jdbc
> javadocs for ResultSet class.
> On Dec 14, 2010 8:46 PM, "Patrick Meyer" <me...@gmail.com> wrote:
> > What is the best way to handle missing values. For example, suppose I
> have
> > an array that I want to insert into a table, like double[] row = {1.0,
> 2.0,
> > MISSING, 4.0} where MISSING indicates a value that is missing. (I realize
> > this is not a valid double value). I have been using a prepared statement
> to
> > set a null value anytime I have missing data like, pstmt.setNull(i+1,
> > Types.DOUBLE); However, the problem is that using rs.getDouble(3) returns
> a
> > value of zero instead of null. The problem is that zero is a legitimate
> > double value, not a missing or null value. Is it better to inset data
> using
> > Double.NAN like pstmt.setDouble(i+1, Double.NaN);? What is the best way
> to
> > handle missing data?
> >
> > Thanks
>

Re: inserting missing values

Posted by Peter Ondruška <pe...@gmail.com>.
You need to check using wasNull method whether the value is null. See jdbc
javadocs for ResultSet class.
On Dec 14, 2010 8:46 PM, "Patrick Meyer" <me...@gmail.com> wrote:
> What is the best way to handle missing values. For example, suppose I have
> an array that I want to insert into a table, like double[] row = {1.0,
2.0,
> MISSING, 4.0} where MISSING indicates a value that is missing. (I realize
> this is not a valid double value). I have been using a prepared statement
to
> set a null value anytime I have missing data like, pstmt.setNull(i+1,
> Types.DOUBLE); However, the problem is that using rs.getDouble(3) returns
a
> value of zero instead of null. The problem is that zero is a legitimate
> double value, not a missing or null value. Is it better to inset data
using
> Double.NAN like pstmt.setDouble(i+1, Double.NaN);? What is the best way to
> handle missing data?
>
> Thanks