You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Stephen Scheck <st...@yahoo.com> on 2009/08/04 06:54:09 UTC

Positional Parameters

Can iBATIS support simple positional parameters for inserts? I want to do something like:

<sqlMap namespace="MyObject">
  <insert id="PERSIST">
    INSERT INTO my_table (f1, f2, f3) VALUES (?, ?, ?)
  </insert>
</sqlMap>

executor.startBatch();
for (int objNum = 0; objNum < MAX_OBJ_NUM; objNum++) {
    Object[] args = new Object[] {
        objNum,
        val1,
        val2
    };

    executor.insert("PERSIST", args);
}

executor.executeBatch();
// etc

In the real case that I'm trying to implement, my fields come from several sources and I'd
prefer to avoid creating an inner class just to make the data conform to a JavaBean.

Thanks.


      

Re: Positional Parameters

Posted by Sheile <sh...@gmail.com>.
Hi.

One of solution is this:

<sqlMap namespace="MyObject">
  <insert id="PERSIST" parameterClass="List">
    INSERT INTO my_table (f1, f2, f3) VALUES
    <iterate open="(" close=")" conjunction=",">
        #[]#
    </iterate>
  </insert>
</sqlMap>

Above solution use java.util.List, I don't know that how to use the Object[].

2009/8/4 Stephen Scheck <st...@yahoo.com>:
> Can iBATIS support simple positional parameters for inserts? I want to do
> something like:
>
> <sqlMap namespace="MyObject">
>   <insert id="PERSIST">
>     INSERT INTO my_table (f1, f2, f3) VALUES (?, ?, ?)
>   </insert>
> </sqlMap>
>
> executor.startBatch();
> for (int objNum = 0; objNum < MAX_OBJ_NUM; objNum++) {
>     Object[] args = new Object[] {
>         objNum,
>         val1,
>         val2
>     };
>
>     executor.insert("PERSIST", args);
> }
>
> executor.executeBatch();
> // etc
>
> In the real case that I'm trying to implement, my fields come from several
> sources and I'd
> prefer to avoid creating an inner class just to make the data conform to a
> JavaBean.
>
> Thanks.
>
>
>

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