gpt4 book ai didi

java - 为什么 SQLite 数据库中该字段没有更新?

转载 作者:行者123 更新时间:2023-12-01 14:20:28 25 4
gpt4 key购买 nike

我知道我错过了一些简单的事情。我制作了一个网站管理器,它使用 SQLite 来跟踪 ftp 地址、登录详细信息、主目录、url 等。我有一个让用户选择和编辑的 Activity站点的详细信息 单击“更新”按钮时,它会更新数据库中站点的行,但是我无法保存的唯一数据库值是网站远程目录的 _remoteHomeDir var。为什么这个值没有更新?

siteManUpdateBtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
_address = siteManFTPAddress.getText().toString();
_username = siteManFTPUsername.getText().toString();
_password = siteManFTPPassword.getText().toString();
String port = siteManFTPPort.getText().toString();
_port = Integer.parseInt(port);
_url = siteManHome.getText().toString();
_remoteHomeDir = siteManHome.getText().toString();
Toast.makeText(SiteManager.this, "Update", Toast.LENGTH_LONG).show();

myDb.updateRow(_rowId, _name, _name, _isLive, _address, _username, _password, _port, _url,_remoteHomeDir);
model.clear();
adapter.notifyDataSetChanged();
displayRecords();
}
});

DBAdapter.java

public boolean updateRow(long rowId, String name, String homedir,
int islive, String address, String username, String password,
int port, String url, String rhome) {
String where = KEY_ROWID + "=" + rowId;

/*
* CHANGE 4:
*/
// TODO: Update data in the row with new fields.
// TODO: Also change the function's arguments to be what you need!
// Create row's data:
ContentValues newValues = new ContentValues();
newValues.put(KEY_NAME, name);
Log.d("tag", "there is something happening here: " + name);
newValues.put(KEY_HOME, homedir);
Log.d("tag", "there is something happening here: " + homedir);
newValues.put(KEY_LIVE, islive);
Log.d("tag", "there is something happening here: " + islive);
newValues.put(KEY_ADDRESS, address);
Log.d("tag", "there is something happening here: " + address);
newValues.put(KEY_USERNAME, username);
Log.d("tag", "there is something happening here: " + username);
newValues.put(KEY_PASSWORD, password);
Log.d("tag", "there is something happening here: " + password);
newValues.put(KEY_PORT, port);
Log.d("tag", "there is something happening here: " + port);
newValues.put(KEY_URL, url);
Log.d("tag", "there is something happening here: " + url);
newValues.put(KEY_RHOME, rhome);
Log.d("tag", "there is something happening here: " + rhome);
// newValues.put(KEY_PASSIVE, passive);
// Insert it into the database.
Log.d("tag", "there is something happening here: " + db.toString());
return db.update(DATABASE_TABLE, newValues, where, null) != 0;
}

最佳答案

看起来您正在从 edittext 站点ManHome 读取 _url 和 _remoteHomeDir 的相同值。这可能是一个错误,并且可能是您在 GUI 中有单独的编辑文本

即:

_url = siteManHome.getText().toString();
_remoteHomeDir = siteManHome.getText().toString();

也许您想从不同的字段获取_remoteHomeDir

关于java - 为什么 SQLite 数据库中该字段没有更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17624357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com