如何更新特定行

时间:2017-05-11 09:38:53

标签: java android android-sqlite

p人的对象。

p.setFname(etname.getText().toString());

p.setLname(etfname.getText().toString());

p.setPassword(etpass.getText().toString());

p.setBirthday(spinnerDay.getSelectedItem().toString() + "/"
+spinnerMonth.getSelectedItem().toString() + "/" + spinnerYear.getSelectedItem().toString());

现在我如何把新名称和传递以及我之前在数据库中所有内容放在一起。

这是我的数据库:

public class DBHelper extends SQLiteOpenHelper{

    private static final String DATABASE_NAME = "users.db";
    private static final int DATABASE_VERSION = 1;

    public static final String TABLE_NAME = "all_users";
    public  static final String NAME = "name";
    public  static final String FNAME = "fname";
    public  static final String EMAIL = "email";
    public  static final String PASS = "pass";
    public  static final String BDAY = "bday";
    public  static final String GENDER = "gender";

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null,DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        String SQL_Create="CREATE TABLE "+TABLE_NAME+" (";
        SQL_Create+=NAME+" TEXT, ";
        SQL_Create+=FNAME+" TEXT, ";
        SQL_Create+=EMAIL+" TEXT PRIMARY KEY, ";
        SQL_Create+=PASS+" TEXT, ";
        SQL_Create+=BDAY+" TEXT, ";
        SQL_Create+=GENDER+" TEXT); ";

        sqLiteDatabase.execSQL(SQL_Create);

1 个答案:

答案 0 :(得分:-1)

尝试更新名称和密码,即:。

ContentValues vContentValues = new ContentValues();
vContentValues.put("NAME", "coral1235");
vContentValues.put("PASS", "1234");
sqLiteDatabase.update(TABLE_NAME, vContentValues, null, null)

编辑:如果您想要替换特定行,则必须编写条件。将最后一行替换为电子邮件所在的行,即coral1235@mail.com:

sqLiteDatabase.update(TABLE_NAME, vContentValues, EMAIL + "=?" , new String[]{"coral1235@mail.com"});