1

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

5
  • Could you not just use JDBC and then write the result using BufferedWriter? Commented Mar 13, 2013 at 10:04
  • Why do you need spring batch to do this? You could very well query the DB with spring jdbc and then write the output to a file. Commented Mar 13, 2013 at 10:06
  • Do you have sample code for buffered writer? Commented Mar 13, 2013 at 10:17
  • What have you tried? Consider reading this. Commented Mar 13, 2013 at 10:20
  • How to write jdbctemplate to get resuleset from query? Commented Mar 13, 2013 at 10:35

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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>

2 Comments

As i am new to spring, i am not able to ubderstand above code
You can refer this below link for how to right JDBC template. static.springsource.org/spring/docs/current/…. For Spring batch File you can refer java.dzone.com/news/spring-batch-hello-world-1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.