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

点点圈 提交于 2020-02-03 02:10:56

问题


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.


回答1:


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();
}



回答2:


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



来源:https://stackoverflow.com/questions/6451765/how-to-export-and-save-tables-to-csv-from-access-database-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!