ResultSet.get throws java.sql.SQLException: Invalid operation at current cursor position

Here I own a derby database in which the table has the name PDF

And i have in my cod :

*private static Connection conn = null;

*private static Statement stmt = null;

in table PDF these columns exist :

-Dir VARCHAR(1000) NOT NULL

-Author VARCHAR(300)

-Title VARCHAR(300) NOT NULL

-Date date

-Image blob

-PageNumber INT

Here I have a function that will retrieve the title and image from the database :

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();
    }

}

And when called, I get this error :

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

Here in the main method I made a connection to the database and called the previous function :

    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);
}

I want a solution to this problem, please and thank you everyone

Answer

Semicolon after while(rs.next());. Remove it and it should work fine.

Leave a Reply

Your email address will not be published. Required fields are marked *