Question: I am using Java. I have a requirement. I am getting 20000 records from database and I need to *write them into a CSV file.* The problem is the data that is retrieved from database has 22 columns and many values will have commas in them.

How can I write the values with comma into a CSV file using Java?

Also, I tried using Apache POI to write the data to excel, but it is taking a long time to write 20000 records. So, I am planning to write data into CSV file. Is this a good approach?

Answer: 
Double quote the entire text field (column) if there's an embedded comma:

```
0, 1, "2,3", 4

```

It's not a bad idea to quote text values anyway.
I highly recommend that you use this nice library (that I did NOT write). <http://opencsv.sourceforge.net/>

It will handle all your CSV problems.