在 getString 中转换 localDate 时出错
Getting error in converting localDate in getString
我正在尝试从数据库中获取选定的数据,其中 presentationDateStart
和 presentationDateEnd
是 localdate
这是我的 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);
我正在尝试从数据库中获取选定的数据,其中 presentationDateStart
和 presentationDateEnd
是 localdate
这是我的 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);