2016-07-14 17 views
0

我将一些数据存储在csv文件中。当我在复制DAO绿色这个数据然后用倒逗号符号的数据是给SQLite的异常如何在csv文件中存储引号,然后将该数据复制到greendao中android

Caused by: android.database.sqlite.SQLiteException: near "s": syntax error (code 1): , while compiling: INSERT INTO CATEGORIES (_id, SNO, SINDHI, HINDI ,ENGLISH, DRAWABLE, AUDIO, CATEGORY) values(188,9,'सस्','सास','Wife\'s or Husband\'s Mother','R.drawable.blank','R.raw.saas','Relatives'); 
                       at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 
                       at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:886) 
                       at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:497) 
                       at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 
                       at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) 
                       at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) 
                       at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663) 
                       at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594) 

我想要的符号,所以我不能在文件中的任何改变。 请帮助将这些符号存储在greendao中。这里是我的一些代码:

InputStream inputStream = getResources().openRawResource(R.raw.animals); 
      InputStreamReader csvStreamReader = new InputStreamReader(inputStream); 
      BufferedReader buffer = new BufferedReader(csvStreamReader); 
      String tableName = "CATEGORIES"; 
      String columns = "_id, SNO, SINDHI, HINDI ,ENGLISH, DRAWABLE, AUDIO, CATEGORY"; 
      String str1 = "INSERT INTO " + tableName + " (" + columns + ") values("; 
      String str2 = ");"; 

      SQLiteDatabase db; 
      DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "category-db", null); 
      db = helper.getWritableDatabase(); 
      db.beginTransaction(); 
      String line; 
      int count=0; 
      try { 
       while ((line = buffer.readLine()) != null) { 
        StringBuilder sb = new StringBuilder(str1); 
        String[] str = line.split(","); 
        sb.append(count + ","); 
        sb.append(str[0] + ","); 
        sb.append("'" + str[1] + "',"); 
        sb.append("'" + str[2] + "',"); 
        sb.append("'" + str[3] + "',"); 
        sb.append("'" + str[4] + "',"); 
        sb.append("'" + str[5] + "',"); 
        sb.append("'" + str[6] + "'"); 
        sb.append(str2); 
        db.execSQL(sb.toString()); 
        count++; 
       } 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      db.setTransactionSuccessful(); 
      db.endTransaction(); 

回答

相关问题