Android SQLiteDatabase插入方法只能工作一次

时间:2014-03-03 15:41:23

标签: android sqlite insertion

我真的不知道我的代码发生了什么。起初,我能够将记录插入到我的表中,然后在我的第二次尝试中它只是不运行。请帮忙。我通过意图传递了用户名,这很有效。

第一

    String pass = txtpass.getText().toString();
    String repass = txtpass2.getText().toString();
    String secA = txtans.getText().toString();
    String secQ = txtQ.getSelectedItem().toString();

    Message.message(this, pass+"and"+repass);


    if(pass.equals(repass))
    {

        long id = mh.insertNewAccount(username, pass, secQ, secA);

        if(id < 0)
            Message.message(this, "Unsuccesful");
        else
        {
            Message.message(this, "You may now logged in! Enjoy your experience!");
            Intent intent = new Intent(this, MainScreen.class);

            Bundle bnd=new Bundle();
            bnd.putString("username", username);            
            intent.putExtras(bnd);

            txtpass.setText("");
            txtpass2.setText("");
            txtans.setText("");
            startActivity(intent);
        }
    }
    else
    {
        Message.message_short(this, "Password didn't match!");
        txtpass.setText("");
        txtpass2.setText("");
    }


}

第二次 - insertNewAccount()函数

        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(MyHelper.USER_ID, "");
        contentValues.put(MyHelper.USER_USERNAME, name);
        contentValues.put(MyHelper.USER_PASSWORD, pass);
        contentValues.put(MyHelper.USER_SECANS, secA);
        contentValues.put(MyHelper.USER_SECQUE, secQ);

        long id = db.insert(MyHelper.TABLE_USERS, null, contentValues);
        db.close();
        return id;

0 个答案:

没有答案
相关问题