• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Mike London

csv output using spring-jdbctemplate during fetching multiple rows

Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using spring jdbctemplate to interact with Oracle database. For fetching multiple rows for a given condition, I want to store the result in a csv file having Column names as the header.

I tried few ways -

In customizedrowmapper, I am fetching the rows from result set and setting the fields in Bean class. I could not find any easy way to convert from bean to csv file. As I dont have access to bean class code.

2nd way I found was to writer ResultSet directly to csv file like below using opencsv library.

This is working okay, but it is skipping one row while writing to csv. I tried few queries. Manually, I can see 4 rows in the result, but in the CSV, it stores only three rows. Anyone faced a similar issue?

Or any other way we can achieve the same, without manually getting each record from ResultSet and making it comma-separated string and storing in file.
Posts: 9697
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you check if the first row of the ResultSet is not in the output? Maybe you called rs.next() once and the CSVWriter is calling rs.next() again thus skipping the first row?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic