1

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.

3 Answers 3

3

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();
}
Sign up to request clarification or add additional context in comments.

Comments

1

You could use opencsv http://opencsv.sourceforge.net

Comments

0

A complete example is here:

https://github.com/NACHC-CAD/access-to-csv-tool

This code includes complete examples in the test code and does a complete export of the northwind data base.

See the class AccessToCsvUtil for the code to convert a single table to a .csv file.

See the class WriteToCsvIntegration test to see code that exports all of the tables in the database.

This utility is based on the ucanaccess jdbc tool and the Apache commons-csv tool.

    <dependency>
        <groupId>net.sf.ucanaccess</groupId>
        <artifactId>ucanaccess</artifactId>
        <version>4.0.4</version>
    </dependency>


    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-csv</artifactId>
        <version>1.8</version>
    </dependency>

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.