- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在运行时遇到这个异常:
SQLite Exception: near "=": syntax error (code 1): , while compiling: UPDATE person_table SET person_name=? WHERE _id =
下面我发布了与此相关的代码。我在下面的代码中提到了错误行 51 和第 56 行。
堆栈跟踪:
12-23 02:02:19.060: E/SQLiteLog(3011): (1) near "=": syntax error
12-23 02:02:19.060: D/AndroidRuntime(3011): Shutting down VM
12-23 02:02:19.060: W/dalvikvm(3011): threadid=1: thread exiting with uncaught exception (group=0xb3a8bba8)
12-23 02:02:19.100: E/AndroidRuntime(3011): FATAL EXCEPTION: main
12-23 02:02:19.100: E/AndroidRuntime(3011): Process: com.android.timesheet, PID: 3011
12-23 02:02:19.100: E/AndroidRuntime(3011): android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: UPDATE person_table SET person_name=? WHERE _id =
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1572)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1520)
12-23 02:02:19.100: E/AndroidRuntime(3011): at com.android.timesheet.database.PersonDatabaseHelper.updateData(PersonDatabaseHelper.java:51)
12-23 02:02:19.100: E/AndroidRuntime(3011): at com.android.timesheet.ModifyMember.onClick(ModifyMember.java:56)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.view.View.performClick(View.java:4438)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.view.View$PerformClick.run(View.java:18422)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.os.Handler.handleCallback(Handler.java:733)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.os.Handler.dispatchMessage(Handler.java:95)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.os.Looper.loop(Looper.java:136)
12-23 02:02:19.100: E/AndroidRuntime(3011): at android.app.ActivityThread.main(ActivityThread.java:5017)
12-23 02:02:19.100: E/AndroidRuntime(3011): at java.lang.reflect.Method.invokeNative(Native Method)
12-23 02:02:19.100: E/AndroidRuntime(3011): at java.lang.reflect.Method.invoke(Method.java:515)
12-23 02:02:19.100: E/AndroidRuntime(3011): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
12-23 02:02:19.100: E/AndroidRuntime(3011): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
12-23 02:02:19.100: E/AndroidRuntime(3011): at dalvik.system.NativeStart.main(Native Method)
PersonDatabaseHelper.java:
public class PersonDatabaseHelper {
private static final String TAG = PersonDatabaseHelper.class.getSimpleName();
// database configuration
// if you want the onUpgrade to run then change the database_version
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "mydatabase.db";
// table configuration
private static final String TABLE_NAME = "person_table"; // Table name
private static final String PERSON_TABLE_COLUMN_ID = "_id"; // a column named "_id" is required for cursor
private static final String PERSON_TABLE_COLUMN_NAME = "person_name";
private static final String PERSON_TABLE_COLUMN_PIN = "person_pin";
private DatabaseOpenHelper openHelper;
private SQLiteDatabase database;
// this is a wrapper class. that means, from outside world, anyone will communicate with PersonDatabaseHelper,
// but under the hood actually DatabaseOpenHelper class will perform database CRUD operations
public PersonDatabaseHelper(Context aContext) {
openHelper = new DatabaseOpenHelper(aContext);
database = openHelper.getWritableDatabase();
}
public void insertData (String aPersonName, String aPersonPin) {
// we are using ContentValues to avoid sql format errors
ContentValues contentValues = new ContentValues();
contentValues.put(PERSON_TABLE_COLUMN_NAME, aPersonName);
contentValues.put(PERSON_TABLE_COLUMN_PIN, aPersonPin);
database.insert(TABLE_NAME, null, contentValues);
}
public int updateData(String member_id, String memberName) {
ContentValues cvUpdate = new ContentValues();
cvUpdate.put(PersonDatabaseHelper.PERSON_TABLE_COLUMN_NAME, memberName);
int i = database.update(PersonDatabaseHelper.TABLE_NAME, cvUpdate, --->51th line Error
PersonDatabaseHelper.PERSON_TABLE_COLUMN_ID + " = " + member_id, null);
return i;
}
public void deleteData(String memberID) {
database.delete(PersonDatabaseHelper.TABLE_NAME, PersonDatabaseHelper.PERSON_TABLE_COLUMN_ID + "="
+ memberID, null);
}
public Cursor getAllData () {
String buildSQL = "SELECT * FROM " + TABLE_NAME;
Log.d(TAG, "getAllData SQL: " + buildSQL);
return database.rawQuery(buildSQL, null);
}
// this DatabaseOpenHelper class will actually be used to perform database related operation
private class DatabaseOpenHelper extends SQLiteOpenHelper {
public DatabaseOpenHelper(Context aContext) {
super(aContext, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
// Create your tables here
String buildSQL = "CREATE TABLE " + TABLE_NAME + "( " + PERSON_TABLE_COLUMN_ID + " INTEGER PRIMARY KEY, " +
PERSON_TABLE_COLUMN_NAME + " TEXT, " + PERSON_TABLE_COLUMN_PIN + " TEXT )";
Log.d(TAG, "onCreate SQL: " + buildSQL);
sqLiteDatabase.execSQL(buildSQL);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
// Database schema upgrade code goes here
String buildSQL = "DROP TABLE IF EXISTS " + TABLE_NAME;
Log.d(TAG, "onUpgrade SQL: " + buildSQL);
sqLiteDatabase.execSQL(buildSQL); // drop previous table
onCreate(sqLiteDatabase); // create the table from the beginning
}
}
}
ModifyMember.java:
public class ModifyMember extends Activity implements OnClickListener {
EditText et;
Button edit_bt, delete_bt;
String member_id;
PersonDatabaseHelper dbcon;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.modify_member);
dbcon = new PersonDatabaseHelper(getApplicationContext());
// dbcon.open();
et = (EditText) findViewById(R.id.edit_mem_id);
edit_bt = (Button) findViewById(R.id.update_bt_id);
delete_bt = (Button) findViewById(R.id.delete_bt_id);
Intent i = getIntent();
String memberID = i.getStringExtra("memberID");
String memberName = i.getStringExtra("memberName");
member_id=memberID;
// member_id = Long.parseLong(memberID);
et.setText(memberName);
edit_bt.setOnClickListener(this);
delete_bt.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.update_bt_id:
String memName_upd = et.getText().toString();
dbcon.updateData(member_id, memName_upd); ----> 56th line error
this.returnHome();
break;
case R.id.delete_bt_id:
dbcon.deleteData(member_id);
this.returnHome();
break;
}
}
public void returnHome() {
Intent home_intent = new Intent(getApplicationContext(),
NewProjects.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(home_intent);
}
}
任何人都可以帮我解决这个问题。谢谢。
最佳答案
改变这个
database.update(PersonDatabaseHelper.TABLE_NAME, cvUpdate, --->51th line Error
PersonDatabaseHelper.PERSON_TABLE_COLUMN_ID + " = " + member_id, null);
进入
database.update(PersonDatabaseHelper.TABLE_NAME, cvUpdate,
PersonDatabaseHelper.PERSON_TABLE_COLUMN_ID + " =?" , new String[]{member_id});
关于java - 编译 : near "=": syntax error (code 1): , WHERE _id = 时出现 SQLite 异常 : UPDATE person_table SET person_name=?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27616100/
这个问题已经有答案了: node.js mongodb .. the (immutable) field '_id' was found to have been altered (5 个回答) 已关
db.books.update({bookId:"123461"},{$set:{"bookPrice":"6.23"}}) 我收到错误: update { q: { bookId: "1234
使用典型的 _id 列并连接表并在创建游标时选择所有列,将导致包含多个 _id 列的游标。 要访问特定的 _id 列,则需要使用实际偏移量,而不是列名。 使用硬编码的偏移量可能会有问题,它使代码更难阅
我使用 ASP .NET MVC4 WebAPI 并且我有一些类(class) public class Recipe { [BsonId] [BsonRepresentation(B
我正在尝试为 MongoDB 中的 _id 字段使用 UUID。 我有一个包装器结构来保存我的记录,如下所示: type mongoWrapper struct { ID uuid.
在 CodeIgniter 的 MongoDB 中进行更新时,出现以下错误: Type: MongoWriteConcernException Message: localhost:27017: Af
我想启动分片。如您所知,分片键非常重要。我发现,MongoDB doesn't ensure unique _id field values when using a shard key other
当我在ES 6.3.2上使用以下内容进行搜索时,没有问题: {“查询”:{“match_phrase_prefix”:{“_ id”:“ZX-bLmsBFOiwdS-Iwr24”}}} 但是,当我在E
我想运行以下查询: Group.find({program: {$in: [...]}}).lean().select('_id') 然后不得到回复: [{_id: ...}, {_id: ...},
我已将我的 ID 重命名为 _id,但仍然得到列“_id”不存在 ...我错过了什么吗? MyDatabaseelper.java public class MyDatabaseHelper exte
所以当我使用 int location = cursor.getColumnIndex(_ID) 它总是返回零,尽管 long locationId = cursor.getlong(getColum
我有一个看起来像这样的路径 path: '/speakers/singleDetails/:_id' 和一个具有这样的字段的架构 speakerId: { type: String,
userSchema={ username: { type: String, required: true, unique: true }, password: {
我正在尝试使用 updateOne 方法更新文档: UpdateResult r = coll.updateOne( eq("_id", id), this.getMapper().m
例如: 我有一个收藏“故事”其中每个文档的形式为: { '_id': 'story': } 现在每当我有一个故事时,如果它已经存在于“故事”中,我想要它的“_id”,否则插入一个带有“故事
这是我的 users.js(routes) for(var zz =0;zz < d.length; zz++){ temp
我在 Nodejs 中有一个数组,其中包含需要检索的 mongoDB 文档的 document _id 值。因此,我需要以这样的方式查询 mongoDB,使其返回 _id 值与我想要传入查询的数组中至
正如您在 NodeJS 代码中看到的那样,我正在从 URL 中提供的 Postman token 中获取用户,但我正在努力从给定的 token 号中取回 _id 属性。我想要的是decoded._id
我是 Android 新手。我有一个 SQLite 后端,其中每一行都是唯一的(想想一个人)。然后,我在每个人的 ListView 中显示这些数据。单击 ListView 项时,它将转到 subvie
他们是否都引用了联系人的同一个唯一 contactId? 最佳答案 他们应该这样做,但不能保证联系人是否已同步或聚合。您可能想尝试使用 LOOKUP_KEY相反。 关于Android dev : Ph
我是一名优秀的程序员,十分优秀!