2017-02-26 149 views
-1

您好我想插入我的sqlite數據庫中的值,但我得到「無法識別的令牌」字節數組的最後一個值異常。這裏是代碼:android sqlite:插入查詢語法錯誤

public void insertImage(String userName, String userMob, String meterReading, String readingAddress, String readingRemark, String readingDate , byte[] imageBytes) { 
     try { 
      mDb.execSQL("INSERT INTO " + IMAGES_TABLE +"(" + USER_NAME + ", " + USER_MOB + ", " + METER_READING_TEXT + ", " + READING_REMARKS + ", " + READING_DATE + ", " + IMAGE + ")" + 
        " VALUES (" + userName + ", " + userMob + ", " + meterReading + ", " + readingAddress + ", " + readingRemark + ", " + readingDate + ", " + imageBytes + ");"); 
     } 
     catch (Exception ex){ 
      ex.printStackTrace(); 
      Log.e("-----","dasdasdas"); 
     } 
     } 
+3

使用參數化查詢。這樣,你就不會有這樣的問題。 –

+0

學習這個http://stackoverflow.com/questions/1324641/cant-insert-byte-into-mysql-using-java –

+0

SQL中的字符串必須是**引號**。 –

回答

0

看來你在值

try { 
     mDb.execSQL("INSERT INTO " + IMAGES_TABLE + 
      "(" + USER_NAME + ", " + 
      USER_MOB + ", " + 
      METER_READING_TEXT + ", " + 
      READING_REMARKS + ", " + 
      READING_DATE + ", " + 
      IMAGE + ")" + 
      " VALUES (" + userName + ", " + 
      userMob + ", " + 
      meterReading + ", " + 
      readingAddress + ", " + 
      readingRemark + ", " + 
      readingDate + ", " + 
      imageBytes + ");"); 
    } 

6進入第7,但元件的兩個子句中的數量必須

+0

爲什麼downvote ...可能這不是唯一的錯誤,但是對於由op提供的代碼是有效的suggestio – scaisEdge