Hello everybody,

First time to post and I am a beginner with JAVA.

With the query I only want 20 rows as I stated in de SQL query.

If I do this

Code:
while(rs.next(){
       //Do something
}
it comes with the following error message:

java.sql.SQLException: [Microsoft][ODBC-stuurprogrammabeheer] Ongeldige cursorstatus

//-> This is dutch it means: [ODBC-Drivermanager] No legal cursorstate. //think that has to do with:

Code:
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)

at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)

at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3908)

at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5702)

at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:356)

at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:413)

at alarmcentrale.akties.getRecentList(akties.java:63)

at alarmcentrale.frmRecent.windowOpened(frmRecent.java:87)

at java.awt.Window.processWindowEvent(Window.java:1118)

at javax.swing.JFrame.processWindowEvent(JFrame.java:266)

at java.awt.Window.processEvent(Window.java:1079)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


It crashes because it only has 20 records in it's resultset and rs.next() is still true but there's no data. If I do the following code I get a Resultset of 24 rows. That is strange in my opinion.
Code:
            ResultSet rs = db.openConnection("SELECT TOP 20 * FROM Melding ORDER BY Datum, Tijd");
            //System.out.println(rs.isBeforeFirst());
            //rs.first();
            //rs.relative(9);
            rs.last();
            recordCount = rs.getRow();
            rs.beforeFirst();
            rs.next();
            for(int j=0;j<recordCount;j++){
                zone = rs.getString("Zone");
                datum = rs.getDate("Datum");
                tijd = rs.getTime("Tijd");
                plaats = rs.getString("Plaats");
                adres = rs.getString("Adres");
            
                rij = zone + " " + datum + " " + tijd + " " + plaats + " " +
                      adres;
                System.out.println(rij + " " + i);
                lijst.add(rij);
                rij = "";
                rs.next();
            }
What am I doing wrong?
Greetings.