PreparedStatement.setBigDecimal should accept a null value or not?

PreparedStatement.setBigDecimal should accept a null value or not?

Post by Kaz. Sasayam » Thu, 25 Apr 2002 17:54:01



I'm using PostgreSQL JDBC driver and annoyed as I cannot pass a null
value to PreparedStatement.setBigDecimal.  If I pass a null value to the
method, I always get an exception.

According to the JDBC spec, I think the method must accept a null value
and pass a SQL NULL to the database, but I may be wrong.  So is it a bug
in the JDBC driver, or my misunderstanding of the spec?

Thanks in advance.

--
"Free software is not for free."

Hyper Linux Systems (Hypercore Software Design, Ltd.)
<URL:http://www.hypercore.co.jp/>

 
 
 

PreparedStatement.setBigDecimal should accept a null value or not?

Post by Lee Fesperma » Fri, 26 Apr 2002 05:00:02



> I'm using PostgreSQL JDBC driver and annoyed as I cannot pass a null
> value to PreparedStatement.setBigDecimal.  If I pass a null value to the
> method, I always get an exception.

> According to the JDBC spec, I think the method must accept a null value
> and pass a SQL NULL to the database, but I may be wrong.  So is it a bug
> in the JDBC driver, or my misunderstanding of the spec?

To set a database null with PreparedStatement use setNull(). Passing a Java null is the
wrong thing to do.

--
Lee Fe*an, FFE Software, Inc. (http://www.veryComputer.com/)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.veryComputer.com/)

 
 
 

PreparedStatement.setBigDecimal should accept a null value or not?

Post by Kaz. Sasayam » Fri, 26 Apr 2002 18:20:05


Thank you.  So I must always write as this?

BigDecimal value;
//...
if (value == null)
   statement.setNull(1, Types.DECIMAL);
else
   statement.setBigDecimal(1, value);


> To set a database null with PreparedStatement use setNull(). Passing a Java null is the
> wrong thing to do.

--
"Free software is not for free."

Hyper Linux Systems (Hypercore Software Design, Ltd.)
<URL:http://www.hypercore.co.jp/>
 
 
 

PreparedStatement.setBigDecimal should accept a null value or not?

Post by Lee Fesperma » Sat, 27 Apr 2002 05:58:25



> Thank you.  So I must always write as this?

> BigDecimal value;
> //...
> if (value == null)
>    statement.setNull(1, Types.DECIMAL);
> else
>    statement.setBigDecimal(1, value);


> > To set a database null with PreparedStatement use setNull(). Passing a Java null is the
> > wrong thing to do.

Yes, that seems like reasonable code.

--
Lee Fe*an, FFE Software, Inc. (http://www.veryComputer.com/)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.veryComputer.com/)

 
 
 

PreparedStatement.setBigDecimal should accept a null value or not?

Post by Kaz. Sasayam » Sat, 27 Apr 2002 11:39:59


Then, what is "If a Java null is passed to any of the setter methods
that take a Java object, the parameter will be set to JDBC NULL."
(13.2.2.3 in JDBC 3.0 spec) saying?

If I must use setNull to set a JDBC NULL, this sentence is meaningless,
isn't it?  Could you clarify the meaning of it?


> Yes, that seems like reasonable code.

--
"Free software is not for free."

Hyper Linux Systems (Hypercore Software Design, Ltd.)
<URL:http://www.hypercore.co.jp/>
 
 
 

PreparedStatement.setBigDecimal should accept a null value or not?

Post by Kaz. Sasayam » Sat, 27 Apr 2002 11:52:48


Also, "Getting Started with the JDBC API"
<http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/GettingStartedT...>
says in 6.1.5, "A JDBC NULL will also be sent to the database when a
Java null value is passed to a setXXX method (if it takes Java objects
as arguments)."

Does it contradict what you say?


> Then, what is "If a Java null is passed to any of the setter methods
> that take a Java object, the parameter will be set to JDBC NULL."
> (13.2.2.3 in JDBC 3.0 spec) saying?

> If I must use setNull to set a JDBC NULL, this sentence is meaningless,
> isn't it?  Could you clarify the meaning of it?


>> Yes, that seems like reasonable code.

--
"Free software is not for free."

Hyper Linux Systems (Hypercore Software Design, Ltd.)
<URL:http://www.hypercore.co.jp/>
 
 
 

PreparedStatement.setBigDecimal should accept a null value or not?

Post by Lee Fesperma » Sat, 27 Apr 2002 15:15:30



> Also, "Getting Started with the JDBC API"
> <http://www.veryComputer.com/;
> says in 6.1.5, "A JDBC NULL will also be sent to the database when a
> Java null value is passed to a setXXX method (if it takes Java objects
> as arguments)."

> Does it contradict what you say?


> > Then, what is "If a Java null is passed to any of the setter methods
> > that take a Java object, the parameter will be set to JDBC NULL."
> > (13.2.2.3 in JDBC 3.0 spec) saying?

It doesn't contradict what I say, because not all drivers support it, as the OP
indicates. How about...

"For maximum portability, use setNull() to set a database null."

--
Lee Fe*an, FFE Software, Inc. (http://www.veryComputer.com/)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.veryComputer.com/)

 
 
 

PreparedStatement.setBigDecimal should accept a null value or not?

Post by Kaz. Sasayam » Wed, 01 May 2002 13:41:35


Now I understand what you say.  I can modify the JDBC driver for my
current project.  Thanks.


> It doesn't contradict what I say, because not all drivers support it, as the OP
> indicates. How about...

> "For maximum portability, use setNull() to set a database null."

--
"Free software is not for free."

Hyper Linux Systems (Hypercore Software Design, Ltd.)
<URL:http://www.hypercore.co.jp/>