android sqlite:插入查询语法错误

时间:2017-02-26 19:07:05

标签: java android sql database sqlite

您好我正在尝试在我的sqlite数据库中插入值,但我得到了#34;无法识别的令牌"用于字节数组的最后一个值异常。这是代码:

 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");
        }
        }

1 个答案:

答案 0 :(得分:0)

似乎你有6个条目进入子句但7个值进入

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 + ");");
    }

两个子句中的元素数必须匹配