0

The java code should generate a csv file from the result of a select query.

Say example select * from employee;. The output of the query should be in csv file in the destination path mentioned in the code.

Please help.

2

3 Answers 3

4

Don't do it in Java. Any decent database already provides builtin facilities for this. It won't be any more efficient in Java than the DB does. Just consult its documentation for export facilities. As you didn't mention which one you're using, I'll just give a MySQL targeted example: LOAD DATA INFILE.

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

Comments

0

I'm not sure what your trouble is. Generating CSV files is pretty much trivial in any language that supports file I/O. Parsing CSV files is where things get interesting.

1 Comment

Generating CSV is not trivial. What do you do when one of the values you want to output contains a comma? e.g. "Hello, world!" Double quotes? e.g. 'He said: "Hello, world!"' Escaped double quotes? And so on..
0

Skaffman made a good comment... you can check out other posts in SO about CSV parsers. For example, check out OpenCSV.

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.