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 Mon, 05 Jul 2004 20:07:18 GMT
--- Ronald Dauster <rpd@ronald-dauster.de> wrote:
> I think every driver will accept "stmt.setNull" given the correct type 
> as second argument.
> Based on this assumption, I see three possible ways to go:
> 
> In theory (i. e. with jdk1.4 and conforming drivers)
> stmt.setNull(i + 1, stmt.getParameterMetaData().getParameterType(i +
> 1));
> should provide the correct type for the null value.
> 
> In practise, any type might be better than Types.OTHER. I can imagine 
> two approaches
> used by the driver:
>  - ignore the type, then any typecode is as good as Types.OTHER
>  - verify the typecode: then is certainly has to be a type supported by 
> the database
>    and (not knowing the correct type) ideally one that can be converted 
> to the
>    columns real type.  In this case, the best choice will probably be 
> Types.VARCHAR.
> 
> 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,
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.  

FYI, Oracle's driver doesn't work with Types.OTHER either but it accepted
every other type I tried (INTEGER, VARCHAR, etc).

David

> 
> Ronald
> 
> >It would be nice if every driver accepted null in setObject but I don't
> >think that's the case.  If we could find a common way to set null
> >parameters in DB2, Oracle, SQL Server, MySQL, and Postgres we could
> >implement fillStatement to use it.  Until then, the QueryRunner
> subclass
> >approach is the only solution.
> >
> >David
> >
> >[...]
> >
> >>My solution was create a QueryRunner
> >>subclass, where I overridden
> >>fillStatement() method like this:
> >>
> >>            if (params == null) {
> >>                return;
> >>            }
> >>
> >>            for(int i = 0; i <
> >>params.length; i++) {
> >>                stmt.setObject(i + 1,
> >>params[i]);
> >>            }
> >>
> >>[...]
> >>
> >> <>Thanks,
> >>
> >> Rafael Ubiratam Clemente Afonso
> >> r.u.c.afonso@uol.com.br
> >>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 



	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
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