commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Graham <grahamdavid1...@yahoo.com>
Subject Re: [DBUtils] SQL Server null - Not implemented (type is java.sql.Types.OTHER)
Date Tue, 06 Jul 2004 00:20:14 GMT
--- Ronald Dauster <rpd@ronald-dauster.de> wrote:
> David Graham wrote:
> 
> >--- Ronald Dauster <rpd@ronald-dauster.de> wrote:
> >  
> >
> >>[...]
> >>
> >>As an alternative to trying to guess the correct type, there could be 
> >>typed null-values
> >>that can optionally be used by a client of QueryRunner.  Something
> along
> >>
> >>the lines
> >>public class Nulls {
> >>    public static final Nulls VARCHAR  = new Nulls(Types.VARCHAR);
> >>    ....
> >>    public int getType() {...}
> >>}
> >>
> >>and in fillStatement
> >>if (params[i] instanceof Nulls) {
> >>    setNull(i+1, ((Nulls) param[i]).getType());
> >>} else if (params[i] != null) {
> >>    setObject
> >>} else {
> >>    setNull
> >>}
> >>    
> >>
> >
> >I'm not sure we need an enum Nulls class to wrap Types.* constants. 
> IMO,
> >  
> >
> The purpose of the enum is to be used as element of the params array 
> which needs Objects and
> Types.VARCHAR ist an int. But I agree that it is a rather cumbersome to 
> use and not exactly in
> the spirit of dbutils.
> 
> >it would be more straightforward to have a QueryRunner.setNullType(int)
> >method where you could pass in Types.VARCHAR. 
> QueryRunner.fillStatement()
> >would then use your type instead of Types.OTHER.  
> >
> >  
> >
> Good enough, if the dbutils client _knows_ which dataabase it is working
> 
> with. Not so good, if the
> Datasource is externally configured.
> 
> In addition, the class is documented to be thread-safe _and_ can be used
> 
> with different connections.
> Adding state to the class with setNullType  will create a race condition
> 
> in the (admittely contrived)
> case where one instance of QueryRunner is used with Connections to 
> databases that require
> different null types.
> 
> >FYI, Oracle's driver doesn't work with Types.OTHER either but it
> accepted
> >every other type I tried (INTEGER, VARCHAR, etc).
> >
> >  
> >
> I need to do a few portability tests against several DBMS anyway and 
> could add that to my list
> (i. e. wich type works), but not before next week and definitely not 
> agains DB2 or Postgres.
> If someone can fill the gaps, maybe we find a type that works on all 
> major databases.


That would be great!  Also, please check what happens if you just pass
null into setObject() instead of using setNull().

Thanks,
David


> >
> Ronald


		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message