我有这个功能应该更新我的 SQLite 数据库中的余额。参数为 Balance balance。我有一个 Balance 课程,我猜它是用来提供帮助的,但我对此并不熟悉。我已经习惯了这样说 updateBalance(int id, String amount) 有人可以向我解释一下这里发生了什么吗?SQLite 世界的新手。
我的 updateBalance 功能:
//Updating single Balance
public int updateBalance(Balance balance){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_AMOUNT, balance.getAmount());
// updating row
return db.update(TABLE_BALANCE, values, KEY_ID + " = ?",
new String[] { String.valueOf(balance.getID()) });
}
我的余额类:
package com.example.budge_it2;
public class Balance {
//private variables
int _id;
String _amount;
//Empty constructor
public Balance(){
}
//Constructor
public Balance(int id, String amount){
this._id = id;
this._amount = amount;
}
public Balance(int id){
this._id = id;
}
//getting ID
public int getID(){
return this._id;
}
//Setting id
public void setID(int id){
this._id = id;
}
//getting amount
public String getAmount(){
return this._amount;
}
//setting amount
public void setAmount(String amount){
this._amount = amount;
}
}