4

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.

2
  • Is there some reason why you can't use mysqldump? Commented Jan 20, 2010 at 20:50
  • Maybe he wants to do it programmatically? I came across this question because I want to give users of our web app the ability to dump search results to CSV. Commented Nov 12, 2012 at 18:52

3 Answers 3

4

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

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

Comments

2

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.

Comments

2

If you are using MySQL take a look at mysqldump

Comments

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.