db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@apache.org>
Subject Re: SQL Exception
Date Wed, 01 Mar 2006 18:37:22 GMT
Craig L Russell wrote:

> I have to say I don't understand the rationale for throwing an 
> exception here. Looking at the stack trace, I agree with Bernt that  the
> user is calling setObject(column, null). What I don't agree with  is
> that there is any ambiguity as to what the user means.
> The setObject javadoc sez:
> The JDBC specification specifies a standard mapping from Java Object 
> types to SQL types. The given argument will be converted to the 
> corresponding SQL type before being sent to the database....This  method
> throws an exception if there is an ambiguity, for example, if  the
> object is of a class implementing more than one of the interfaces  named
> above.
> more below...

> I think that for parameters that implement multiple interfaces, there 
> is ambiguity. Where is the ambiguity in trying to set a column of  type
> VARCHAR to null?

Technically the setObject() method or any setXXX is not setting a column

It is defining a value that will be transmitted to the database engine,
the database engine sets the column value, using the transmitted value.

For the explict setXXX methods they have comments like:

> The driver converts this to an SQL TIME value when it sends it to the

Thus a setTime() on a VARCHAR() column is really doing a send the value
as a TIME to the database engine, the engine then figures out how/if to
do conversions. Drivers can optimize this, performing converions etc. in
the driver, but they need to behave outwardly as the spec says, which is
JDBC is transmitting values as the *application requested* to the
database engine.

For setObject("col_name", null) the application is not providing any
information on how the value (NULL) is to be sent to the database. Since
SQL doesn't handle untyped NULLs, the database engine cannot accept it,
therefore it's disallowed.

A setObject("col_name", new Integer(3)) is well defined as there is a
JDBC defined mapping from java.lang.Integer to SQL INTEGER.


View raw message