ResultSet.get throws java.sql.SQLException: 当前光标位置的操作无效
ResultSet.get throws java.sql.SQLException: Invalid operation at current cursor position
这里我拥有一个 derby 数据库,其中 table 的名称为 PDF
我的鳕鱼里有 :
*private static Connection conn = null;
*private static 语句 stmt = null;
在 table PDF 中存在这些列:
-Dir VARCHAR(1000) NOT NULL
-作者 VARCHAR(300)
-标题 VARCHAR(300) NOT NULL
-日期日期
-图像 blob
-PageNumber INT
这里我有一个函数可以从数据库中检索标题和图像:
public static void getPdfBoxInfo()
{
try
{
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM PDF");
while(rs.next());
{
String Title = rs.getString("Title"); //this is 111 line
byte[] imageByte = rs.getBytes("Image");
Image image = new Image(new ByteArrayInputStream(imageByte));
readingNowController p = new readingNowController();
HBox hbox = p.creatPdfbox(Title,image);
p.addBookToMenu(hbox);
System.out.println("data is get");
}
rs.close();
stmt.close();
}
catch (SQLException sqlExcept)
{
sqlExcept.printStackTrace();
}
}
调用时,出现此错误:
java.sql.SQLException: Invalid cursor state - no current row.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:225)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:220)
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(EmbedConnection.java:3215)
at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(ConnectionChild.java:155)
at org.apache.derby.impl.jdbc.EmbedResultSet.checkOnRow(EmbedResultSet.java:336)
at org.apache.derby.impl.jdbc.EmbedResultSet.getColumnType(EmbedResultSet.java:354)
at org.apache.derby.impl.jdbc.EmbedResultSet.getString(EmbedResultSet.java:697)
at org.apache.derby.impl.jdbc.EmbedResultSet.getString(EmbedResultSet.java:1342)
at ReadEra.DataBase.databaseMain.getPdfBoxInfo(databaseMain.java:111)
at ReadEra.Main.main(Main.java:28)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: ERROR 24000: Invalid cursor state - no current row.
at org.apache.derby.shared.common.error.StandardException.newException(StandardException.java:300)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
... 22 more
在 main 方法中,我连接了数据库并调用了之前的函数:
public static void main(String[] args) throws SQLException, IOException {
System.out.println("Start conn");
createConnection();
System.out.println("Start get");
getPdfBoxInfo();
System.out.println("close");
shutdown();
launch(args);
}
我想要解决这个问题的方法,谢谢大家
while(rs.next());
后的分号。删除它,它应该可以正常工作。
这里我拥有一个 derby 数据库,其中 table 的名称为 PDF
我的鳕鱼里有 :
*private static Connection conn = null;
*private static 语句 stmt = null;
在 table PDF 中存在这些列:
-Dir VARCHAR(1000) NOT NULL
-作者 VARCHAR(300)
-标题 VARCHAR(300) NOT NULL
-日期日期
-图像 blob
-PageNumber INT
这里我有一个函数可以从数据库中检索标题和图像:
public static void getPdfBoxInfo()
{
try
{
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM PDF");
while(rs.next());
{
String Title = rs.getString("Title"); //this is 111 line
byte[] imageByte = rs.getBytes("Image");
Image image = new Image(new ByteArrayInputStream(imageByte));
readingNowController p = new readingNowController();
HBox hbox = p.creatPdfbox(Title,image);
p.addBookToMenu(hbox);
System.out.println("data is get");
}
rs.close();
stmt.close();
}
catch (SQLException sqlExcept)
{
sqlExcept.printStackTrace();
}
}
调用时,出现此错误:
java.sql.SQLException: Invalid cursor state - no current row.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:115)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:225)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:220)
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(EmbedConnection.java:3215)
at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(ConnectionChild.java:155)
at org.apache.derby.impl.jdbc.EmbedResultSet.checkOnRow(EmbedResultSet.java:336)
at org.apache.derby.impl.jdbc.EmbedResultSet.getColumnType(EmbedResultSet.java:354)
at org.apache.derby.impl.jdbc.EmbedResultSet.getString(EmbedResultSet.java:697)
at org.apache.derby.impl.jdbc.EmbedResultSet.getString(EmbedResultSet.java:1342)
at ReadEra.DataBase.databaseMain.getPdfBoxInfo(databaseMain.java:111)
at ReadEra.Main.main(Main.java:28)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: ERROR 24000: Invalid cursor state - no current row.
at org.apache.derby.shared.common.error.StandardException.newException(StandardException.java:300)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory.java:170)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:75)
... 22 more
在 main 方法中,我连接了数据库并调用了之前的函数:
public static void main(String[] args) throws SQLException, IOException {
System.out.println("Start conn");
createConnection();
System.out.println("Start get");
getPdfBoxInfo();
System.out.println("close");
shutdown();
launch(args);
}
我想要解决这个问题的方法,谢谢大家
while(rs.next());
后的分号。删除它,它应该可以正常工作。