Hello:

I have a suggestion. We could create a interface called
FillerStatement. This would have a only method: void
fillStatement(PreparedStatement stmt, Object[] params). The
basic implementation of this interface will work like
fillStatement() now in QueryRunner. Like this:

public class BasicFillerStatement implements FillerStatement {

   public void fillStatement(PreparedStatement stmt, Object[]
params) {
        if (params == null) {
            return;
        }

        for (int i = 0; i < params.length; i++) {
            if (params[i] != null) {
                stmt.setObject(i + 1, params[i]);
            } else {
                stmt.setNull(i + 1, Types.OTHER);
            }
        }
   }

}

We would have a SQLServerFillerStatement with solution that I
used:

public class SQLServerFillerStatement implements
FillerStatement {

   public void fillStatement(PreparedStatement stmt, Object[]
params) {
        if (params == null) {
            return;
        }

        for (int i = 0; i < params.length; i++) {
           stmt.setObject(i + 1, params[i]);
        }
   }

}

And we would have a OracleFillerStatement,
MySQLFillerStatement, FirebirdFillerStatement, and so on. In
this form we could be a "personalized" way to attend any kind
of database (or JDBC driver) features, mainly with null
parameters.
How do we use it? In QueryRunner implementation we would had
a attribute for FillerStatement. By default this attribute
will implement BasicFillerStatement:

   private FillerStatement fillerStatement = new
BasicFillerStatement();

And we would have a setFillerStatement() method:

   public void setFillerStatement(FillerStatement filler) {
      this.fillerStatement = filler;
   }

In update(), query() and batch() methods, it will call
fillStatement() method from fillerStatement attribute:

   this.fillerStatement.fillStatement(stmt, params);

So, if I am using a SQLServer like database, We could do this:

   QueryRunner runner = new QueryRunner();
   runner.setFillerStatement(new SQLServerFillerStatement());

Well, what do you think?

Thanks,

Rafael Ubiratam Clemente Afonso
[EMAIL PROTECTED]
---------------------------------
Where is Debug?
Debug is on the Table!

---------- In�cio da mensagem original -----------

      De: &quot;David Graham&quot; [EMAIL PROTECTED]
    Para: &quot;Jakarta Commons Users List&quot; commons-
[EMAIL PROTECTED]
      Cc:
    Data: Mon, 5 Jul 2004 11:02:40 -0700 (PDT)
 Assunto: Re: [DBUtils] SQL Server null - Not implemented
(type is  java.sql.Types.OTHER)

> 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
>
>
>
> --- "Rafael U. C. Afonso" <[EMAIL PROTECTED]> wrote:
> > Hello:
> > 
> > I had a problem like related by Henri
> > Yandell (see
> >
> http://www.mail-archive.com/commons-
[EMAIL PROTECTED]/msg42819.html),
> > but instead use Oracle I am using SQL
> > Server. When I try insert a Null
> > parameter in a Insert Query I get this
> > message: "Not implemented (type is
> > java.sql.Types.OTHER)". I am using
> > jTds driver, but MS official driver
> > has the same problem (But does not
> > explain about Types.Other).
> > I read original Source of jTds and I
> > see that this message above is thrown
> > from a method called
> > createParameterMapping() from
> > ParameterUtils class. I don't
> > understand why they made this, but
> > anyway it is a problem from driver,
> > not form QueryRunner.
> > 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]);
> >             }
> >
> > I don't verify if current parameter is
> > null or not. And this works.
> > What do you think?
> >
> > Thanks,
> >
> > Rafael Ubiratam Clemente Afonso
> > [EMAIL PROTECTED]
> > ---------------------------------
> > Where is Debug?
> > Debug is on the Table!
> >
> >
>
______________________________________________________________
____________
> > Acabe com aquelas janelinhas que pulam na sua tela.
> > AntiPop-up UOL - ? gr?tis!
> > http://antipopup.uol.com.br/
> >
> >
> >
> > ----------------------------------------------------------
-----------
> > To unsubscribe, e-mail: commons-user-
[EMAIL PROTECTED]
> > For additional commands, e-mail: commons-user-
[EMAIL PROTECTED]
> >
> >
>
>
>
>       
>
> __________________________________
> Do you Yahoo!?
> New and Improved Yahoo! Mail - 100MB free storage!
> http://promotions.yahoo.com/new_mail
>
> ------------------------------------------------------------
---------
> To unsubscribe, e-mail: commons-user-
[EMAIL PROTECTED]
> For additional commands, e-mail: commons-user-
[EMAIL PROTECTED]
>
>

 
__________________________________________________________________________
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - � gr�tis!
http://antipopup.uol.com.br/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to