gpt4 book ai didi

java - SQLite:java.sql.SQLException:结果集是TYPE_FORWARD_ONLY?

转载 作者:行者123 更新时间:2023-11-29 04:25:54 28 4
gpt4 key购买 nike

在我发布我的问题之前,我尝试了所有解决方案但我无法解决我的问题。任何人都可以帮助我找到解决方案吗?

我正在尝试从表“Email”中获取数据,但每次它都会调用此异常

java.sql.SQLException: ResultSet is TYPE_FORWARD_ONLY at org.sqlite.jdbc4.JDBC4ResultSet.first(JDBC4ResultSet.java:402) at HMDao.EmailDao.FindString(EmailDao.java:144) at hmproject.StartingController.initialize(StartingController.java:103) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at hmproject.HMProject.start(HMProject.java:34) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)

这是我的代码:

 public Email FindString(String ID) {

Email email = null;

String querySelectEmployer = "SElECT Email,Password FROM Email";

try {

ResultSet resultSet = Dbaconnection.getConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY).executeQuery(querySelectEmployer);


if (resultSet.first()) {

email = new Email(resultSet.getString("Email"), resultSet.getString("Password"));
}
resultSet.close();

} catch (SQLException ex) {
ex.printStackTrace();
}

return email;

}

最佳答案

发生这种情况是因为 first() 指的是数据集中的“绝对位置”,它仅适用于游标结果集。

由于不需要重新定位,只需将光标移动到初始记录,将 first() 的调用替换为 next() 即可:

if (resultSet.next()) {
email = new Email(resultSet.getString("Email"), resultSet.getString("Password"));
}

关于java - SQLite:java.sql.SQLException:结果集是TYPE_FORWARD_ONLY?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46334145/

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