Resultset rs=stmt.executeQuery("select count(*) from feedsca group by score order by score");
Utilizzando il codice java sopra riportato, sto recuperando i conteggi delle righe dalla tabella denominata feedsCA.Utilizzo di Resultset nel programma Java
Durante il tentativo di recupero dei conteggi utilizzando rs.getInt (1), rs.getInt (2), rs.getInt (3), che si conclude con un errore che dice come sotto,
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The result set has no current row.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.verifyResultSetHasCurrentRow(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getterGetColumn(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getInt(Unknown Source)
at SimpleMail.main(SimpleMail.java:151)
UPDATE :
L'eccezione di cui sopra è stata risolta.
Ma ottengo la seguente eccezione, per la quale non so il motivo. Si prega di avvisare.
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.verifyValidColumnIndex(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getterGetColumn(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getInt(Unknown Source)
at SimpleMail.main(SimpleMail.java:152)
Ecco come ho aggiornato il mio programma. Trovami un modo logico in quanto posso capire bene che il ciclo sottostante non funzionerà come richiesto.
rs=stmt.executeQuery("select count(*) from feedsca group by score order by score");
while(rs.next()){
pw.printf(rowFormat, rs.getLong(1),"0",rs.getLong(2),rs.getLong(3));}
Grazie Bozho! Gentilmente aggiornami anche sulla mia recente eccezione. Vedere la mia domanda aggiornata – LGAP
@LGAP: la query è 'SELECT COUNT (*) ...', che restituisce solo 1 valore. Quindi l'unico indice valido è 1, ecco perché si lamenta che l'indice 2 è fuori portata. – casablanca
@casablanca e Bozho Per favore, trova la mia domanda aggiornata ... – LGAP