• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to append data in CSV file using CSVWriter?

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to append data of two tables in a resultset. I have tried the below code but not getting the desired output only the first resultset data i.e. the first table data


I am getting Count as 0 in all three places Guide me please.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

HappyS Singh wrote:...I am getting Count as 0 in all three places Guide me please.




The count is zero because you are getting a result set with no results from your SQL query.
 
Happy S Singh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Despite of count 0, I get all records of second query in CSV file.
But I want both output..means 1st queries output appended with 2nd queries output.
 
Marshal
Posts: 28424
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But... the getRow() method returns the current row number. Which will always be zero when you haven't read any rows from the ResultSet, as in the code posted.
 
Happy S Singh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay.I got about getRow().
Now how to append the result in CSV file.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:But... the getRow() method returns the current row number. Which will always be zero when you haven't read any rows from the ResultSet, as in the code posted.



Yeah, I mis-read the method name (I thought is was getRows()) and was gonna edit my post. Stopped when I saw responses so it wouldn't be ninja-editing.
 
Paul Clapham
Marshal
Posts: 28424
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to append to a file, then you should use the FileWriter constructor with the parameter which specifies that. The constructor you chose always overwrites the data in the file, if it already exists.
 
Ranch Hand
Posts: 679
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or just open the file before the for loop and close it afterwards, rather than opening and closing it every time round the loop.
 
Happy S Singh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks alot Paul Clapham and Adrian Burkett.
 
Paul Clapham
Marshal
Posts: 28424
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adrian Burkett wrote:Or just open the file before the for loop and close it afterwards, rather than opening and closing it every time round the loop.



Yes, I think that's a better fix than my suggestion.
 
Happy S Singh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I am able to write it in file..but when the ouput is large ,I get
exception
 
Happy S Singh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Resolved..Just moved ps = conn1.prepareStatement(results[i].toString()); outside the for loop
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic