SQLiteException: unrecognized token:
在往数据库更新数据时出现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);
}
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。