【问题标题】:Android import CSV to SQLite not first rowAndroid将CSV导入SQLite而不是第一行
【发布时间】:2014-06-04 22:16:13
【问题描述】:

我想将数据导入 SQLite 数据库表,CSV 文件中的数据,但 CSV 文件的第一行包含我不想导入的信息。我能怎么做?这是我用来导入文件的方法:

File root = Environment.getExternalStorageDirectory();
 File exportDir = new File(root.getAbsolutePath());
 File csvFile = new File(exportDir, getString(R.string.app_name)+".csv");

 try {
ContentValues cv = new ContentValues();

CSVReader dataRead = new CSVReader(new FileReader(csvFile));
String[] vv = null;
  while((vv = dataRead.readNext())!=null) {
   cv.clear();
   SimpleDateFormat postFormater = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat currFormater  = new SimpleDateFormat("dd-MM-yyyy");
      String eDDte;
try
`{
Date nDate = currFormater.parse(vv[0]);
            eDDte = postFormater.format(nDate);
            cv.put(EntrateUsciteTable.DATA,eDDte);
        }
         catch (Exception e) {
        }

SQLiteDatabase db = mHelper.getWritableDatabase();
 db.insert(EntrateUsciteTable.TABLE_NAME,null,cv);
}
dataRead.close();
} catch (Exception e) {
Log.e("TAG",e.toString());
}

【问题讨论】:

    标签: java android sqlite csv import


    【解决方案1】:

    以计数器为例:

    int counter = 0;
    while((vv = dataRead.readNext())!=null) {
        if(counter == 0) {
            continue;
            counter++;
        } else {
           // Do the insert
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-03
      • 2013-05-16
      • 1970-01-01
      • 2013-02-05
      • 2015-09-23
      • 2012-09-14
      • 2012-08-29
      • 2023-03-13
      相关资源
      最近更新 更多