Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - java.sql.SQLException: Resultset esaurito ?
Forum - Java - java.sql.SQLException: Resultset esaurito ?

Avatar
symonx80 (Normal User)
Pro


Messaggi: 107
Iscritto: 30/07/2009

Segnala al moderatore
Postato alle 11:14
Giovedì, 11/02/2010
Ciao,
ho un semplice programma java che esegue una connessione ad un db oracle e effettua delle select su di esso.
Il programma dopo un poò che in runtime si interrompe con il seguente errore

java.sql.SQLException: Resultset esaurito

e non ne capisco il motivo.

Uso sempre lo stesso oggetto Connection . Uso un oggetto Statement stmt che chiudo ogni volta che termino di lavorare sulla query e resultSet differenti per ogni query, resulSet che chiudo insieme all'oggetto Statement al termine delle operazioni.
Devo scorrere un migliaio direcord ma dopo circa 300 l'elaborazione si interompe con quel messaggio.
Dove sbaglio?


Allego il codice

Codice sorgente - presumibilmente Java

  1. public static void main(String [] args){
  2.  
  3.                 Connection con = null;
  4.                 Statement stmt = null;
  5.                 ResultSet rs = null;
  6.                 PreparedStatement prep = null;
  7.                
  8.                 ResultSet rsRecuperaUtente = null;
  9.                 ResultSet rsDatiRagSociale = null;
  10.                 ResultSet rsDatiConsumo = null;
  11.                 ResultSet rsImportoConsumo = null;
  12.                 ResultSet rsDatiTestata = null;
  13.                 ResultSet rsDatiDettaglio = null;
  14.                
  15.                 PrintStream ps = null;
  16.                
  17.  
  18.                
  19.                 //Connessione al database Oracle
  20.                 try {
  21.                         Class.forName("oracle.jdbc.driver.OracleDriver");
  22.                
  23.                         // Create a connection to the database
  24.                         String serverName = "##########";
  25.                         String portNumber = "1521";
  26.                         String sid = "####";
  27.                         String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
  28.                         String username = "###";
  29.                         String password = "###";
  30.                         con = DriverManager.getConnection(url, username, password);
  31.  
  32.  
  33.                         //apro il file su cui andare a srivere
  34.                         ..........................
  35.                         .....................................
  36.  
  37.  
  38.                         stmt = con.createStatement();
  39.                         rs = stmt.executeQuery("SELECT U23C_BOL FROM KK_TESUTF2");
  40.                         int contaBollette = 0;
  41.                        
  42.                         while (rs!=null && rs.next()) {
  43.                                
  44.                         String numBolletta = rs.getString("U23C_BOL");
  45.                         ps.print("................................
  46.                         contaBollette++;
  47.                        
  48.                        
  49.                         stmt = con.createStatement();
  50.                         rsRecuperaUtente = stmt.executeQuery("select u32c_ute from KK_TESUTF2 where u23c_bol='" + numBolletta +"'");
  51.                         rsRecuperaUtente.next();
  52.                         int codUtente = rsRecuperaUtente.getInt("u32c_ute");
  53.                         stmt.close();
  54.                         rsRecuperaUtente.close();
  55.                        
  56.                        
  57.                         stmt = con.createStatement();
  58.                         rsDatiRagSociale = stmt.executeQuery("select ac_rg_cli from ce_an_clie where ac_c_cli='" + codUtente + "'");
  59.                         rsDatiRagSociale.next();
  60.                         ps.print.........................
  61.                         stmt.close();
  62.                         rsDatiRagSociale.close();
  63.                        
  64.                         stmt = con.createStatement();
  65.                         rsDatiTestata  = stmt.executeQuery("select * from KK_TESUTF2 where u23c_bol='" + numBolletta +"' ");
  66.                         rsDatiTestata.next();
  67.                         ps.print(rsDatiTestata.getString("U92DE_VIA") +  "      " + rsDatiTestata.getString("U13C_N_CIV") + "   ");
  68.                         ps.print(rsDatiTestata.getString("U92C_CAP") +  "       " + rsDatiTestata.getString("U92C_S_CAP")+  "   " + rsDatiTestata.getString("U92DE_LOCA"));
  69.                         String dataIn = ............
  70.                         String dataFn = .................
  71.                         String dataEmis = .....................
  72.                         ps.print................................................................
  73.                         ps.println("");
  74.                         stmt.close();
  75.                         rsDatiTestata.close();
  76.                        
  77.                         stmt = con.createStatement();
  78.                         rsDatiConsumo = stmt.executeQuery("select (U21Q_L_ATU - U21Q_L_PRE) from ut_bl_cont where u21c_bol = '" + numBolletta +"'");
  79.                         rsDatiConsumo.next();
  80.                         ps.print("....................................................
  81.                         stmt.close();
  82.                         rsDatiConsumo.close();
  83.                        
  84.                         stmt = con.createStatement();
  85.                         rsImportoConsumo = stmt.executeQuery("SELECT U22C_BOL, U22C_IVA, U22C_A_IVA,  SUM(U22VALONUM_E), U22IMIMPOS_E FROM KK_DETUTF2 WHERE U22C_BOL='" + numBolletta + "' and U18DE_VCE like 'IMPORTO GAS%' group by U22C_BOL, U22C_IVA, U22C_A_IVA, U22IMIMPOS_E");
  86.                                 if (rsImportoConsumo!=null) {
  87.                                 rsImportoConsumo.next();
  88.                                 double impConsumo = rsImportoConsumo.getDouble(1);
  89.                         }      
  90.                        
  91.                         stmt.close();
  92.                         rsImportoConsumo.close();
  93.  
  94.  
  95.                         }
  96.  
  97.                
  98.                 } catch (ClassNotFoundException e) {
  99.                         // TODO Auto-generated catch block
  100.                         e.printStackTrace();
  101.                 } catch (SQLException e) {
  102.                         // TODO Auto-generated catch block
  103.                         e.printStackTrace();
  104.                 } catch (FileNotFoundException e) {
  105.                         // TODO Auto-generated catch block
  106.                         e.printStackTrace();
  107.                 }finally{
  108.                         ps.close();
  109.                 }
  110.         }


Ultima modifica effettuata da symonx80 il 11/02/2010 alle 11:16
PM Quote
Avatar
netarrow (Admin)
Guru^2


Messaggi: 2502
Iscritto: 12/05/2004

Segnala al moderatore
Postato alle 19:27
Giovedì, 11/02/2010
Il metodo next ritorna un boolean, dovresti quindi fare un controllo per verificare se ci sono o non ci sono altre righe  da poter leggere.

Se tu vai avanti a prescindere ti lancia un'eccezione.

PM Quote
Avatar
symonx80 (Normal User)
Pro


Messaggi: 107
Iscritto: 30/07/2009

Segnala al moderatore
Postato alle 12:40
Martedì, 16/02/2010
Si grazie, infatti con un while al posto dell'if ho risolto per il meglio

PM Quote