开发者

HSQLDB Statement and Java NaN doubles

I'm currently using HSQLDB to save java data. Within theses datas, there are some Double, and some of them can be of values of NaN (described as 0.0/0.0 in the javadoc). HSQLDB know how to handle these values in setDouble and setFloat of PreparedStatement. The thing is, I have to use a Statement object, not a precompiled stored procedure, and I just can't find a way to make it work.

If you had the tinyest hint, it would be most welcome :)

Thanks.

EDIT : Here's the bunch of code I'm using :

stmt.executeUpdate("insert into Mesh(Id, name, dime开发者_JAVA技巧nsion, meshtype, totalVolume, NumberOfCoarseCell) values (identity(), "  
                             + "'" + name_ + "',"  
                             + dimension_ + "," // this value can be NaN  
                             + "'" + type_.toString() + "',"   
                             + totalVolume_ + "," // this value can be NaN  
                             + numberOfCoarseCells_ + ")");  


You mean you need a way to write a NaN within a SQL statement? The following works for the H2 database:

select sqrt(-1) from dual

However, it doesn't work for Apache Derby and PostgreSQL (I didn't test other databases). For HSQLDB, it no longer works in version 2.1 and newer, unless you set SET DATABASE SQL DOUBLE NAN FALSE.


With HSQLDB 1.8.x you can use (0.0e1/0.0e1) as an expression that returns NaN.

For example:

create table t (d double)
insert into t values (0.0e1/0.0e1) 

For HSQLDB 2.1 and above, an property must be specified with an SQL statement:

SET DATABASE SQL DOUBLE NAN FALSE

Or as a connection property:

hsqldb.double_nan=false
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜