db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Segel" <mse...@segel.com>
Subject RE: SQL Exception
Date Mon, 06 Mar 2006 21:21:15 GMT


> -----Original Message-----
> From: Craig.Russell@Sun.COM [mailto:Craig.Russell@Sun.COM]
> Sent: Friday, March 03, 2006 10:28 PM
> To: Derby Discussion
> Subject: Re: SQL Exception
> 
> Hi Michael,
> 
> I was afraid that you might have missed some context in this thread.
> >
> >> Bernt M. Johnsen wrote (2006-03-01 10:27:57):
> >>
> >
> > To be precise:
> > You may not call setObject("middle_name", null), but you may call
> > one of the following
> >
> > setObject("middle_name", null, java.sql.Types.VARCHAR)
> >    or
> > setNull("middle_name", java.sql.Types.VARCHAR)
> >    or
> > setString("middle_name", null);
> 
> What I'm saying is that if the Derby driver knows that the type of
> the parameter is VARCHAR then there's no reason it has to treat these
> cases differently.
> 
> Craig

[mjs] Looking at what is said, you should not be able to pass in a null
reference in the setObject(), setNull() or setString() methods. If you can,
then I would consider it a bug. (Or does the JDBC spec allow for this
behavior?)

http://java.sun.com/j2se/1.4.2/docs/api/index.html

The database should throw an SQLEXCEPTION if it receives a null reference as
an input parameter.

Actually this discussion really is a moot point.
For consistency you should always use the setNull() method. Not all setXXX()
methods will allow you to pass in a null reference. What you are suggesting
is not clean code.


But hey, what do I know? ;-)
My goal is to write code that is clean enough to have a 10-15+ year lifespan
with as minimal amount of maintenance as possible. 

-Mikey




Mime
View raw message