SQLiteException: unrecognized token:

来源:互联网 发布:邮件服务器软件价格 编辑:程序博客网 时间:2024/06/07 07:07

在往数据库更新数据时出现android.database.sqlite.SQLiteException: unrecognized token: "33xo8cgMSaRqZNs0bS2ol2RxIsqfOKUj8Dyb7sMN" (code 1): , while compiling: update Book1 set face_id =33xo8cgMSaRqZNs0bS2ol2RxIsqfOKUj8Dyb7sMN where image_id=24478

sql语句:

//把faceId插入Book1    public void addFaceId(int imageId,String faceId){        db = mDatabaseHelper.getWritableDatabase();        db.execSQL("update Book1 set face_id ="+faceId+" where image_id="+imageId);}

后发现是字符串没加单引号。

原来sql语句中如果有字符串,必须用单引号‘’把字符串括起来。

例如:update Book1 set face_id ='faceId' where image_id=imageId;

faceId是一个字符串
不能是update Book1 set face_id =faceId where image_id=imageId;

正确的写法应该是:

//把faceId插入Book1    public void addFaceId(int imageId,String faceId){        db = mDatabaseHelper.getWritableDatabase();        db.execSQL("update Book1 set face_id ='"+faceId+"' where image_id="+imageId);}





阅读全文
0 0