gpt4 book ai didi

java - 只查询一个字符串

转载 作者:行者123 更新时间:2023-12-01 12:54:22 26 4
gpt4 key购买 nike

我最近从原始 SQLite 切换到 ORMLite,现在我有一个来自名为 user 的对象的表,其中最大行数始终为 1(始终只有 1 个用户),我如何使用 ORMLite 查询此表中的一个字符串或整数(如 user) id 或散列还是类似?

按照旧的方式,我是这样做的:

public int getCode() {
int result = -1;
if (db != null) {
String rawQuery = "SELECT code FROM settings;";
Cursor crs = db.rawQuery(rawQuery, null);
if (crs != null && crs.getCount() > 0 && crs.moveToNext()) {
result = crs.getInt(crs.getColumnIndex("code"));
}
}
return result;
}

那么 ORMLite 应该是什么样子呢?

最佳答案

您可以引用此示例,取自 ORMLite documentation :

// get our query builder from the DAO
QueryBuilder<Account, String> queryBuilder = accountDao.queryBuilder();
// the 'password' field must be equal to "qwerty"
queryBuilder.where().eq(Account.PASSWORD_FIELD_NAME, "qwerty");
// query for all accounts that have "qwerty" as a password
List<Account> accountList = queryBuilder.query();

关于java - 只查询一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24009301/

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