更改密码 - 更新SQLite数据库 - 没有这样的列

时间:2016-04-09 14:46:50

标签: java android sql eclipse sqlite

我写了一篇我想要更改用户密码的课程。除了事实上它没有这样的列,即使我已经将数据输入到匹配它的数据库中,并且'C3438525'用于登录(它成功地显示它在数据库中很好),我已经将它设置得很好)

我尝试过使用几种不同格式的SQL语句但没有结果

这是课程,如果需要其他课程,请询问,我会粘贴它们。

changePassword.java

public class changePassword extends Activity {  

    SQLiteDatabase checkDB;
    DB db = new DB(this);   
    //Load session name 
    String sessionName;
    String sessionPassword;
    String currentPasswordString;
    String newPassword1String;
    String newPassword2String;
    //Load text fields
    EditText currentPassword;
    EditText newPassword1;
    EditText newPassword2;  

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.changepassword);
        Button changePassword = (Button)findViewById(R.id.changePasswordButton);
        //Load session name
        SharedPreferences preferences = getSharedPreferences("temp", getApplicationContext().MODE_PRIVATE);
        sessionName = preferences.getString("sessionName", ""); 
        sessionPassword = preferences.getString("sessionPassword", ""); 
        currentPassword = (EditText)findViewById(R.id.currentPassword);
        newPassword1 = (EditText)findViewById(R.id.newpassword1);       
        newPassword2 = (EditText)findViewById(R.id.newpassword2);   
    }

    //Mismatched password checking
    public void updatePassword(View v)
    {       
        currentPasswordString = currentPassword.getText().toString();
        newPassword1String = newPassword1.getText().toString();
        newPassword2String = newPassword2.getText().toString();
        Toast.makeText(changePassword.this, sessionName.toString(), Toast.LENGTH_LONG).show();
        Toast.makeText(changePassword.this, newPassword2String.toString(), Toast.LENGTH_LONG).show();
        if (currentPasswordString.equals(sessionPassword))
        {
            if (newPassword1String.equals(newPassword2String))
            {
            checkDB = db.getWritableDatabase();
            checkDB.execSQL("UPDATE Students SET Student_Password=" + newPassword2String + " WHERE CNumber= " + sessionName);
            Log.d("Password", "Changed");
            }
        }
    }

logcat的:

04-09 10:40:23.895: E/AndroidRuntime(2144): FATAL EXCEPTION: main
04-09 10:40:23.895: E/AndroidRuntime(2144): Process: com.example.project, PID: 2144
04-09 10:40:23.895: E/AndroidRuntime(2144): java.lang.IllegalStateException: Could not execute method of the activity
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.view.View$1.onClick(View.java:3823)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.view.View.performClick(View.java:4438)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.view.View$PerformClick.run(View.java:18422)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.os.Handler.handleCallback(Handler.java:733)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.os.Handler.dispatchMessage(Handler.java:95)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.os.Looper.loop(Looper.java:136)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.app.ActivityThread.main(ActivityThread.java:5001)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at java.lang.reflect.Method.invokeNative(Native Method)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at java.lang.reflect.Method.invoke(Method.java:515)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at dalvik.system.NativeStart.main(Native Method)
04-09 10:40:23.895: E/AndroidRuntime(2144): Caused by: java.lang.reflect.InvocationTargetException
04-09 10:40:23.895: E/AndroidRuntime(2144):     at java.lang.reflect.Method.invokeNative(Native Method)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at java.lang.reflect.Method.invoke(Method.java:515)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.view.View$1.onClick(View.java:3818)
04-09 10:40:23.895: E/AndroidRuntime(2144):     ... 11 more
04-09 10:40:23.895: E/AndroidRuntime(2144): Caused by: android.database.sqlite.SQLiteException: no such column: C3438525 (code 1): , while compiling: UPDATE Students SET Student_Password=1234 WHERE CNumber=C3438525
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1672)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1603)
04-09 10:40:23.895: E/AndroidRuntime(2144):     at com.example.project.changePassword.updatePassword(changePassword.java:64)
04-09 10:40:23.895: E/AndroidRuntime(2144):     ... 14 more

1 个答案:

答案 0 :(得分:0)

一些选项:

  • 尝试在SQL语句中的值中添加单引号,例如:

... SET Student_Password =&#39; 1234&#39;在哪里......

  • 您最近可能已对数据库架构进行了更改,请尝试将DBHelper中的数据库版本增加一个(或在您正在使用的设备中重新安装该应用程序)。

  • 检查create语句并验证列名称和类型。