I just want to query data from database and write it into an output file. How can I achieve this using spring batch?
-
Could you not just use JDBC and then write the result using BufferedWriter?David– David2013-03-13 10:04:30 +00:00Commented 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.Anubhab– Anubhab2013-03-13 10:06:25 +00:00Commented Mar 13, 2013 at 10:06
-
Do you have sample code for buffered writer?user2160534– user21605342013-03-13 10:17:49 +00:00Commented Mar 13, 2013 at 10:17
-
What have you tried? Consider reading this.BDM– BDM2013-03-13 10:20:41 +00:00Commented Mar 13, 2013 at 10:20
-
How to write jdbctemplate to get resuleset from query?user2160534– user21605342013-03-13 10:35:39 +00:00Commented Mar 13, 2013 at 10:35
2 Answers
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.
Comments
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>