I want to import a csv(comma delimited) file to sqlite. I save csv file in asset folder and then insert in table... I should to save utf-8 format. When i save csv file without utf-8 format, my application runs without any problems but when i save same csv file in excel and then save in utf-8 format and then to set on asset folder, in insert time, i had a problem, i wrote in below:
android.database.sqlite.SQLiteDatatypeMismatchException: datatype mismatch (code 20)
my code is:
@Override
public void onCreate(SQLiteDatabase db) {
//db=context.openOrCreateDatabase(sDB_Name,Context.MODE_PRIVATE,null);
db.execSQL(sCreate_Table);
createDBFromCSV(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXIST " + MASKANLOC_TABLE);
onCreate(db);
}
private void createDBFromCSV(SQLiteDatabase db) {
AssetManager assetManager = context.getAssets();
try {
InputStream inputStream = assetManager.open(maskanFile);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = "";
String column_value[];
String insert_row = "insert into " + MASKANLOC_TABLE + " (" + COLUMN_ID + "," + COLUMN_LAT + "," + COLUMN_LONG + "," + COLUMN_ADDRESS + "," + COLUMN_CODE + "," + COLUMN_TYPE + "," + COLUMN_UPLOADED + ")" + " values(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")";
while ((line = bufferedReader.readLine()) != null) {
column_value = line.split(";");
String setCommand = String.format(insert_row, column_value[0], column_value[1], column_value[2], column_value[3], column_value[4], column_value[5], column_value[6]);
db.execSQL(setCommand);
}
} catch (IOException e) {
e.printStackTrace();
}
}
Thanks for advises
Aucun commentaire:
Enregistrer un commentaire