Java Reference
In-Depth Information
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql" value="insert into customer (firstName,
middleInitial, lastName, address, city, state, zip) values (?, ?, ?, ?, ?, ?,
?)"/>
<beans:property name="itemPreparedStatementSetter"
ref="preparedStatementSetter"/>
</beans:bean>
<beans:bean id="preparedStatementSetter"
class="com.apress.springbatch.chapter9.
CustomerItemPreparedStatementSetter"/>
<step id="formatStep">
<tasklet>
<chunk reader="customerFileReader" writer="jdbcBatchWriter"
commit-interval="10"/>
</tasklet>
</step>
<job id="formatJob">
<step id="step1" parent="formatStep"/>
</job>
</beans:beans>
Because you already have the JDBC drivers configured in the POM and the dataSource configured
for the JobRepository , all you need to do is execute an mvn clean install and execute the command in
Listing 9-28 to see the results of the updated formatJob .
Listing 9-28. Command to Execute formatJob
java -jar itemWriters-0.0.1-SNAPSHOT.jar jobs/formatJob.xml formatJob
customerFile=/input/customer.csv
The output of this job isn't in a file this time but in the database. You can confirm the execution in
two ways. The first is by going to the database to validate the input. Listing 9-29 shows the results of the
job in the database.
Listing 9-29. Job Results with jdbcBatchWriter
mysql> select * from customer;
+------+-----------+---------------+----------+--------------------------+---
--------+-------+-------+
| id | firstName | middleInitial | lastName | address |
city | state | zip |
+------+-----------+---------------+----------+--------------------------+---
--------+-------+-------+
| 1607 | Richard | N | Darrow | 5570 Isabella Ave |
St. Louis | IL | 58540 |
| 1608 | Warren | L | Darrow | 4686 Mt. Lee Drive |
St. Louis | NY | 94935 |
| 1609 | Barack | G | Donnelly | 7844 S. Greenwood Ave |
 
 
Search WWH ::




Custom Search