Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android sqlite:插入查询语法错误_Java_Android_Sql_Database_Sqlite - Fatal编程技术网

Java android sqlite:插入查询语法错误

Java android sqlite:插入查询语法错误,java,android,sql,database,sqlite,Java,Android,Sql,Database,Sqlite,您好,我正在尝试在sqlite数据库中插入值,但我得到字节数组的最后一个值异常的“无法识别的令牌”。以下是代码: public void insertImage(String userName, String userMob, String meterReading, String readingAddress, String readingRemark, String readingDate , byte[] imageBytes) { try { m

您好,我正在尝试在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");
        }
        }

似乎在子句中有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 + ");");
    }

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

使用参数化查询。这样,您就不会遇到这样的问题。了解此字符串必须在SQL中引用。为什么要向下投票。。。这可能不是唯一的错误,而是对op提供的代码的有效建议