Thanks a lot! Clear. I think I've solved, since the batch seems to do just what I want!![]()
Thanks a lot! Clear. I think I've solved, since the batch seems to do just what I want!![]()
Just a question: since I use a dataSource for JdbcTemplate, could you tell me how to not create and release the connection to the database for each item being processed? If my file has 3000 lines, I will do getConnection and relase connection to the database 3000 times. At the moment I still don't know how to get the connection at row 1 and release it at row 3000. Is it possible to do that?
The only class I've found is SingleConnectionDataSource, but I'm still studying how to use it... Maybe it's just sufficient to use such bean instead of BasicDataSource. Isn't it?
EDIT: actually using the following configuration, the connection is anything but single:
And the Spring Batch in Action manual suggests this approach to hold a single JDBC connection to the database and reuse for each query.Code:<bean id="dataSource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@localhost:1521:test" /> <property name="username" value="USR" /> <property name="password" value="PASS" /> <property name="suppressClose" value="true"/> </bean>![]()
Last edited by fbcyborg; Aug 24th, 2012 at 08:37 AM.
use commons dbcp
the jdbc batch commit is controlled in the step :Code:<bean id="batch-job-data-source" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:url="${db.url}" p:username="${db.username}" p:password="${db.password}" p:maxIdle="10" p:maxActive="100" p:maxWait="10000" p:validationQuery="${db.validationQuery}" p:testOnBorrow="false" p:testWhileIdle="true" p:timeBetweenEvictionRunsMillis="1200000" p:minEvictableIdleTimeMillis="1800000" p:numTestsPerEvictionRun="5" p:defaultAutoCommit="false" p:driverClassName="${db.driverClassName}" />
Code:<batch:chunk reader="jdbc-data-input-reader" processor="item-processor" writer="jdbc-data-input-writer" commit-interval="#{jobParameters['commit.interval']}" />