I have stored some data in MySQL database through a java program. Now I want to export that data from the same program in .csv file.
I know One method of doing this is to get all the fields of one row in variables and then store them in a file by seperating them with a comma(,) and by repeating the same for every row in the database.
But I want to know that Can I export the same data through any other way through java in .csv format.
I used this once it worked for me. http://opencsv.sourceforge.net/
Honestly, unless you want to do something fancy, what you are doing should work
You can Google for a third party CSV library, do the Java querying yourself with sqljdbc.jar or whatever is appropriate to your database, and feed the data to the CSV library.
You might even find a third-party library that can give you a CSV from a SQL query and a JDBC connection.
But if you're going to programmatically implement CSV, please implement it completely, including escaping spaces, quotes, etc. Wikipedia has details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With