This is a known issue with the Oracle driver - not an iBATIS issue.
Returning row counts for batches is optional in the JDBC spec and Oracle
chooses not to implement it. So you will always get 0 from iBATIS when you
use a batch in Oracle. (Oracle returns -2 for the row count which means
success, but no further information. iBATIS translates the -2 to 0)
It sounds like your batching is working as well as possible with Oracle.
Jeff Butler
On Mon, May 12, 2008 at 8:56 AM, Giovanni Cuccu <[EMAIL PROTECTED]>
wrote:
> Hi,
> I've read the iBaits documentation, but I'm still unable to use batch
> api.
> I tried to the following example in order to better understand how to
> get started.
> import java.io.Reader;
> import java.util.HashMap;
> import java.util.Map;
>
> import com.ibatis.common.resources.Resources;
> import com.ibatis.sqlmap.client.SqlMapClient;
> import com.ibatis.sqlmap.client.SqlMapClientBuilder;
>
>
> public class TestIBatisBatch {
>
> /**
> * @param args
> */
> public static void main(String[] args) throws Exception {
>
> String filename="sql-map-config.xml";
> Reader reader=Resources.getResourceAsReader(filename);
> SqlMapClient
> sqlMap=SqlMapClientBuilder.buildSqlMapClient(reader);
>
> try {
> sqlMap.startTransaction();
> sqlMap.startBatch();
> Map map=new HashMap();
> map.put("id", 1L);
> map.put("name", "test 1");
> sqlMap.insert("testiBatis.test_insert",map);
> map.clear();
> map.put("id", 2L);
> map.put("name", "test 2");
> sqlMap.insert("testiBatis.test_insert",map);
> map.clear();
> map.put("id", 3L);
> map.put("name", "test 3");
> sqlMap.insert("testiBatis.test_insert",map);
> int rows=sqlMap.executeBatch();
> System.out.println("inserite " + rows + " righe");
> sqlMap.commitTransaction();
> } catch (Exception e) {
> e.printStackTrace();
> } finally {
> sqlMap.endTransaction();
> }
>
>
> }
>
> }
> here are the relevant config files
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
> "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
>
> <sqlMapConfig>
> <settings useStatementNamespaces="true"/>
>
>
> <transactionManager type="JDBC">
> <dataSource type="SIMPLE">
> <property name="JDBC.Driver"
> value="oracle.jdbc.driver.OracleDriver"/>
> <property name="JDBC.ConnectionURL"
> value="jdbc:oracle:thin:@localhost:1521:orcl"/>
> <property name="JDBC.Password" value="test"/>
> <property name="JDBC.Username" value="test"/>
> <property name="JDBC.DefaultAutoCommit"
> value="false"/>
> </dataSource>
> </transactionManager>
>
> <sqlMap resource="testiBatis.xml"/>
> </sqlMapConfig>
>
> <?xml version="1.0" encoding="UTF-8" ?>
>
> <!DOCTYPE sqlMap
> PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
> "http://ibatis.apache.org/dtd/sql-map-2.dtd">
> <sqlMap namespace="testiBatis">
>
> <insert id="test_insert" parameterClass="java.util.Map">
> insert into modules(id,name) values(#id#,#name#)
> </insert>
>
> </sqlMap>
>
>
> the preceding example insert three rows but I got the message
> inserite 0 righe
> My guess is than batching is not taking place but what I'm missing?
> thanks,
> Giovanni
>
>
> --
> --------------------------------------------------------------------
> "You don't know the power of dark side" - Darth Vader
>