数据库更新
case R.id.updata:
db=myDbHelper.getWritableDatabase();
String selctiontext2=Et_selection.getText().toString();
String username1=Et_username.getText().toString();
String password1 =Et_password.getText().toString();
//把查询到的selctiontext2的名字,改成其它的名字和密码
db.execSQL("update user set username=?,password=? where username=?",new Object[]{username1,password1,selctiontext2});
//下边的代码和上边的一行代码同等,上边的是用sql语句,下边的是系统自带的方法
// ContentValues contentValues=new ContentValues();
// contentValues.put("username",username1);
// contentValues.put("password",password1);
// db.update("user",contentValues,"username=?",new String[]{selctiontext2});//把查询到的selctiontext2的名字,改成其它的名字和密码
db.close();
break;
Anroid Studio数据库更新示例代码
最新推荐文章于 2023-04-23 21:15:58 发布
该段代码展示了如何使用SQLite数据库在Android中更新用户信息。通过获取数据库实例,执行SQL更新语句或使用ContentValues对象,将指定用户名和密码更新到对应的名字下。
167

被折叠的 条评论
为什么被折叠?



