Android sqlite更新表始终返回0 [英] Android sqlite update table always return 0
问题描述
我在这里看到了几个有关在sqlite中进行更新的问题,但无法解决此问题.我无法更新表,它总是给0;
I have seen several questions here related to updating in sqlite, but not able to solve this problem. I am unable to update table, it always give 0;
public void onCreate(SQLiteDatabase db) {
try{
db.execSQL(createTable);
db.execSQL(createQuestionTable);
populateQuestionTable(db);
}
catch( SQLException e)
{
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS alarms" );
onCreate(db);
}
我能够插入和获取数据,但是更新它只是一个问题.
I am able to insert and fetch data, but there is only problem in updating it.
public int updateTable( int r )
{
String row = String.valueOf(r);
Log.d("mydb", "disbale alarm" + " " + row);
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(isDisable, 1);
int result = 0;
try{
result = db.update("alarms", values, keyId+" = ? " ,new String[]{row});
Log.d("result", ""+result);
}
catch(Exception e)
{
e.printStackTrace();
}
db.close();
return result;
}
P.S.我也尝试过execSql()
P.S. I have also tried execSql()
推荐答案
听起来好像没有任何条件与您的条件相符.也许作为测试,您应该将null作为您的where条件(表示更新所有行),并查看是否仍返回0.
It sounds like nothing matches your criteria. Perhaps as a test you should pass null as your where criteria (this signifies update all rows) and see if 0 is still returned.
如果在此之后仍然返回0,我将确保您确实在数据库表中保存了数据.
If 0 is still returned after that I would look to ensure you actually have data saved in your database table.
这篇关于Android sqlite更新表始终返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!