更新android数据库中的值
我的应用程序中有一个设置选项卡,它通过用户的 edittext 获取 int 值并将其存储到数据库中。当用户现在想要更改设置时,应在数据库中更新旧设置。我如何为此编写数据库代码。
下面是我将值保存在数据库中的代码:
DatabaseHelper dha = new DatabaseHelper(this);
SQLiteDatabase db = dha.getWritableDatabase();
Log.d("","Done with database Sqlite");
ContentValues cv = new ContentValues();
EditText editText2 = (EditText) this.findViewById(R.id.editText1);
setTime = editText2.getText().toString();
Log.d(setTime, "This is the setTime value");
cv.put(DatabaseHelper.TIME, setTime);
db.insert("finalP", DatabaseHelper.TIME, cv);
db.close();
I have a settings tab in my application which takes an int value through edittext from user and stores it into the database. When the user now wants to change the setting the old setting should be updated in the database. How do I write the database code for that.
Below is my code to save the value in db:
DatabaseHelper dha = new DatabaseHelper(this);
SQLiteDatabase db = dha.getWritableDatabase();
Log.d("","Done with database Sqlite");
ContentValues cv = new ContentValues();
EditText editText2 = (EditText) this.findViewById(R.id.editText1);
setTime = editText2.getText().toString();
Log.d(setTime, "This is the setTime value");
cv.put(DatabaseHelper.TIME, setTime);
db.insert("finalP", DatabaseHelper.TIME, cv);
db.close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该做这样的事情:
You should do something like this: