Search code examples
javams-accessexport-to-csv

How to export and save tables to .csv from access database in java


I am trying to export a lot of large tables from a MS Access db with java using the jdbc:odbc bridge. I wanted to save these tables to a CSV file first was wondering what would the best way to do this would be? any help would be appreciated.


Solution

  • Fetch the values and write a standard text file line by line separating the values. I#m sure there are some libs for this purpose

    try
    {
     FileWriter writer = new FileWriter("c:\\temp\\MyFile.csv");
     while(result.next())
     {
     for(int i = 0; i < columnSize; i++)
     {
        writer.append(result.getObject(i));
        if(i < columnSize - 1)
           writer.append(',');
     }
     writer.append('\n');
     }
     }
     catch(Exception e)
    {
      e.printStackTrace();
    }