gpt4 book ai didi

java - 基于此方法中的此数据库查询,我需要返回最后一条记录。有时这个查询会返回多条记录

转载 作者:搜寻专家 更新时间:2023-10-30 20:33:41 26 4
gpt4 key购买 nike

//这个查询可以返回多条记录,在多条记录的情况下,总是返回查询的最后一条记录。

public People(int peopleId) {

Prepared Statement SQL= null;
try {
System.out.println("Getting Phone for " + personSerId);
Prepared SQL= new DatabaseController(verbose);

PreparedStatement secureStatement = prepareStatement(sqlStatement);
s
dbConnection.querySecureRecord(SQL);
(((File) ("item")));
theNumber.setPhone((String) dbConnection.getField("phone"));
theNumber.phone(dbConnection.getField("number") == null ? "" : (((String)
}
} catch (Exception masterException) {
System.err.println("Database Query Error in : " + masterException);

return the person;
}

最佳答案

你必须做 3 件事。

  1. 指定排序依据(id、创建日期...):this post says there is no guaranteed ordering if none is specified.
  2. 降序排列,所以列表中的第一件事就是你想要的
  3. 将查询限制为 1

似乎有一个问题是,即使只期望一个结果,数据库 Controller 也会迭代结果集。因此您可能仍然需要从列表中获取“第一个”结果,即使只有一个(或可能没有)要获取。

关于java - 基于此方法中的此数据库查询,我需要返回最后一条记录。有时这个查询会返回多条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53751223/

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