android SQLite项目在模拟器中正常工作但在我的设备中无法正常工作

时间:2013-10-16 18:11:05

标签: android

我的android SQLite项目在模拟器中正常工作但在我的设备中无法正常工作。可能是什么原因?

    SQLiteDatabase myDB= null;
      String TableName = "myTable";

      String Data="";

      /* Create a Database. */
      try {
       myDB = this.openOrCreateDatabase("DatabaseName", MODE_PRIVATE, null);

       /* Create a Table in the Database. */
       myDB.execSQL("CREATE TABLE IF NOT EXISTS "
         + TableName
         + " (Field1 VARCHAR, Field2 INT(3));");

       /* Insert data to a Table*/


 myDB.execSQL("INSERT INTO "
             + TableName
             + " (Field1, Field2)"
             + " VALUES ('Saranga1', 202), ('mani', 300);");

       /*retrieve data from database */
       Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);

       int Column1 = c.getColumnIndex("Field1");
       int Column2 = c.getColumnIndex("Field2");

       // Check if our result was valid.
       c.moveToFirst();
       if (c != null) {
        // Loop through all Results
        do {
         String Name = c.getString(Column1);
         int Age = c.getInt(Column2);
         Data =Data +Name+"/"+Age+"\n";
        }while(c.moveToNext());
       }
       TextView tv = new TextView(this);
       tv.setText(Data);
       setContentView(tv);
      }
      catch(Exception e) {
       Log.e("Error", "Error", e);
      } finally {
       if (myDB != null)
        myDB.close();
      }

这是编码......

 myDB.execSQL("INSERT INTO "
         + TableName
         + " (Field1, Field2)"
         + " VALUES ('Saranga1', 202), ('mani', 300);");

这是我需要帮助的一行...如果我插入一组值,它在模拟器和设备中都能正常工作。  即。,

myDB.execSQL("INSERT INTO "
         + TableName
         + " (Field1, Field2)"
         + " VALUES ('Saranga1', 202);");

这是正常工作....当我试图一次插入多个值集意味着它不在设备中工作。但两种编码在模拟器中都能正常工作....请帮助我......

0 个答案:

没有答案