我正在尝试从表中更改密码,但出现错误。谁能帮我找到解决方案?
这是我的数据库类代码:
public boolean change(String answer, String newpassword) {
String sql = "UPDATE "+DATABASE_TABLE +" SET " + KEY_PASSWORD+ " = '"+newpassword+"' WHERE "+KEY_ANSWER+ " = "+answer;
Cursor cur=db.rawQuery(sql, null);
if (cur != null) {
if(cur.getCount() > 0)
{
return true;
}
}
return false;
}
这是我的安卓代码:
if(quest.change(answer, newpassword)){
Intent login=new Intent(forgot.this, securityLogin.class);
startActivity(login);
} else{
Toast.makeText(forgot.this, "wrong answer",Toast.LENGTH_SHORT).show();
}
这是我的日志:
08-27 13:23:52.735: E/AndroidRuntime(464): FATAL EXCEPTION: main
08-27 13:23:52.735: E/AndroidRuntime(464): java.lang.IllegalStateException: database not open
08-27 13:23:52.735: E/AndroidRuntime(464): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1333)
08-27 13:23:52.735: E/AndroidRuntime(464): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
08-27 13:23:52.735: E/AndroidRuntime(464): at com.inovawe.inwp.securityDB.change(securityDB.java:163)
08-27 13:23:52.735: E/AndroidRuntime(464): at com.inovawe.inwp.forgot$1.onClick(forgot.java:36)
08-27 13:23:52.735: E/AndroidRuntime(464): at android.view.View.performClick(View.java:2408)
08-27 13:23:52.735: E/AndroidRuntime(464): at android.view.View$PerformClick.run(View.java:8816)
08-27 13:23:52.735: E/AndroidRuntime(464): at android.os.Handler.handleCallback(Handler.java:587)
08-27 13:23:52.735: E/AndroidRuntime(464): at android.os.Handler.dispatchMessage(Handler.java:92)
08-27 13:23:52.735: E/AndroidRuntime(464): at android.os.Looper.loop(Looper.java:123)
08-27 13:23:52.735: E/AndroidRuntime(464): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-27 13:23:52.735: E/AndroidRuntime(464): at java.lang.reflect.Method.invokeNative(Native Method)
08-27 13:23:52.735: E/AndroidRuntime(464): at java.lang.reflect.Method.invoke(Method.java:521)
08-27 13:23:52.735: E/AndroidRuntime(464): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-27 13:23:52.735: E/AndroidRuntime(464): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-27 13:23:52.735: E/AndroidRuntime(464): at dalvik.system.NativeStart.main(Native Method)
我得到了答案,下面的代码正在运行
rawQuery("UPDATE "+DATABASE_TABLE +" SET " + KEY_PASSWORD+ " = '"+newpassword+"' WHERE answer=?", new String[]{answer});