gpt4 book ai didi

java - 在 getString 中转换 localDate 时出错

转载 作者:行者123 更新时间:2023-12-01 09:59:24 25 4
gpt4 key购买 nike

我正在尝试从数据库中获取选定的数据,其中presentationDateStartpresentationDateEndlocaldate

这是我的 DAO:

public List<PresentationBean> list() throws SQLException {
List<PresentationBean> presentations = new ArrayList<PresentationBean>();

try (
Connection connection = currentCon.getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT presentationDateStart, presentationDateEnd FROM presentation where ROWNUM=1");
ResultSet resultSet = statement.executeQuery();
) {
while (resultSet.next()) {
PresentationBean presentation = new PresentationBean();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd");
LocalDate startDate = LocalDate.parse("presentationDateStart", formatter);
presentation.setPresentationDateStart(resultSet.getString(startDate)); //ERROR HERE
presentation.setPresentationDateEnd(resultSet.getString("presentationDateEnd")); //ERROR HERE

presentations.add(presentation);
}
}

错误说:

no suitable method found for getString(LocalDate) method ResultSet.getString(int) is not applicable (argument mismatch; LocalDate cannot be converted to int) method ResultSet.getString(String) is not applicable (argument mismatch; LocalDate cannot be converted to String)

我知道 presentationDateEnd 是一个错误,因为我还没有转换它。我首先尝试了 presentationDateStart 但没有成功。我不知道如何转换 localDate。预先感谢您

最佳答案

您的代码毫无意义。而不是:

LocalDate startDate = LocalDate.parse("presentationDateStart", formatter);   
presentation.setPresentationDateStart(resultSet.getString(startDate));

您的意思可能是:

String startDateAsString = resultSet.getString("presentationDateStart");    
LocalDate startDate = LocalDate.parse(startDateAsString, formatter);
presentation.setPresentationDateStart(startDate);

关于java - 在 getString 中转换 localDate 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36936923/

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