user2160534
user2160534

Reputation: 97

Read data from database and write into output .txt file in spring

I just want to query data from database and write it into an output file. How can I achieve this using spring batch?

Upvotes: 1

Views: 3372

Answers (2)

Filipe Cabaco
Filipe Cabaco

Reputation: 41

See this blog, it's great for beginners! http://www.mkyong.com/spring/

There the author gives a clear and easy example on how to use JDBC http://www.mkyong.com/spring/maven-spring-jdbc-example/

Then like Ranu Jain correctly said you use JDBCTemplate in your class to read the information (execute the query you want) by injecting it has a property.

Follow mkyong example and it will be easy.

Upvotes: 1

Ranu Jain
Ranu Jain

Reputation: 577

If you will JDBC template in your context.xml then you will get DB connection by injecting jdbcTemplate in your processor and by using File object you can write the data in any file

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <constructor-arg ref="dataSource"/>
</bean>

Upvotes: 0

Related Questions