ORMLite 获取单个数据库列
ORMLite get single database column
我正在尝试将此 SQL 命令与 Ormlite 一起使用:
select address from receive
使用此代码:
List<Receivers> receiver_address = receiverDao.queryBuilder().selectColumns("address").query();
但是返回的对象是:
1 = {Receivers@830028192208}
address = {String@830028192264} "my new address"
city = null
email = null
telephone = null
mobile = null
name_family = null
national_code = null
postal_code = null
receiver_name = null
id = 2
我只需要此查询中的 address
字段而无需 iterator
例如:
List<String> list = new ArrayList<String>();
for( Receivers lst:receiver_address)
list.add(lst.getAddress());
这个动作怎么做?
您可以在这里使用 RawRowMapper:
List<String> addresses = receiverDao.queryRaw("select address from receive", new RawRowMapper<String>() {
@Override
public String mapRow(String[] columnNames, String[] resultColumns) throws SQLException {
return resultColumns[0];
}
}).getResults();
我正在尝试将此 SQL 命令与 Ormlite 一起使用:
select address from receive
使用此代码:
List<Receivers> receiver_address = receiverDao.queryBuilder().selectColumns("address").query();
但是返回的对象是:
1 = {Receivers@830028192208}
address = {String@830028192264} "my new address"
city = null
email = null
telephone = null
mobile = null
name_family = null
national_code = null
postal_code = null
receiver_name = null
id = 2
我只需要此查询中的 address
字段而无需 iterator
例如:
List<String> list = new ArrayList<String>();
for( Receivers lst:receiver_address)
list.add(lst.getAddress());
这个动作怎么做?
您可以在这里使用 RawRowMapper:
List<String> addresses = receiverDao.queryRaw("select address from receive", new RawRowMapper<String>() {
@Override
public String mapRow(String[] columnNames, String[] resultColumns) throws SQLException {
return resultColumns[0];
}
}).getResults();