IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JDBC Java Discussion :

java.sql.SQLException: L'élément ResultSet n'est pas ouvert.


Sujet :

JDBC Java

  1. #1
    Membre averti Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Points : 355
    Points
    355
    Par défaut java.sql.SQLException: L'élément ResultSet n'est pas ouvert.
    Bonjour tout le monde,

    J'ai une erreur de ce type lorsque j'utilise 2 boucles rs.next() de 2 requêtes différentes:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
    java.sql.SQLException: L'élément ResultSet n'est pas ouvert.  Vérifiez que la fonction de validation automatique est désactivée (OFF).
    	at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
    	at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    	at org.apache.derby.client.am.ResultSet.next(Unknown Source)
    	at vue.GraphiqueEtatPatient.<init>(GraphiqueEtatPatient.java:101)
    	at vue.Fenetre.graphEtatP(Fenetre.java:473)
    	at vue.Fenetre.actionPerformed(Fenetre.java:538)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: org.apache.derby.client.am.SqlException: L'élément ResultSet n'est pas ouvert.  Vérifiez que la fonction de validation automatique est désactivée (OFF).
    	at org.apache.derby.client.am.ResultSet.checkForClosedResultSet(Unknown Source)
    	at org.apache.derby.client.am.ResultSet.nextX(Unknown Source)
    	... 29 more
    Quelqu'un peut-il me dire ce que signifie ce charabia ?

    Voici ce que je fais:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    try {
    			connection = DriverManager.getConnection(URL + USER + PWD);
    			Statement stmt = connection.createStatement();
    			ResultSet rs = stmt.executeQuery("SELECT mesure.*, ref, nom FROM mesure, patient WHERE id_patient=ref");
    			int nbreMesure = 0;
    			int day, month, year;
    			
    			// Creation des lignes
    			TimeSeries mesure_patient = null;
    			//series_ligne_2 = new TimeSeries("Patient 2", Hour.class);
    			dataSet.removeAllSeries();
    			
    			int nbrepatient = 3;//ado.recupRefPatient();
    			for(int n = 1; n<nbrepatient; n++){
    				Statement stm = connection.createStatement();
    				ResultSet res = stmt.executeQuery("SELECT nom FROM patient WHERE ref="+n);
    				while (res.next()){
    					String nom_patient = (String)res.getObject(1);
    					System.out.println("nom_patient: "+nom_patient);
    					while (rs.next()){
    //						int refpatient =  rs.getInt(8);
    //						System.out.println("refpatient: "+refpatient);
    				
    						mesure_patient = new TimeSeries(nom_patient, Hour.class);
    						if (rs.getInt(7)==n){
    							nbreMesure++;
    							System.out.println("nbreMesure: "+nbreMesure);
    					
    							date=(String) rs.getObject(4);
    							glycemie=(Double) rs.getObject(5);
    					
    							day = Integer.parseInt(date.substring(0,2));
    							System.out.println("dat: "+day);
    							month = Integer.parseInt(date.substring(3,5));
    							System.out.println("mois: "+month);
    							year = Integer.parseInt(date.substring(6,10));
    							System.out.println("annee: "+year);
    							System.out.println("glycemie: "+glycemie);
    					
    							mesure_patient.setNotify(true);
    							mesure_patient.add(new Hour(nbreMesure,day,month,year), glycemie);
    						}
    					}
    					// Ajout des ligne dans le dataset
    					dataSet.addSeries(new TimeSeries(nom_patient, Hour.class));
    					//dataSet.addSeries(series_ligne_2);
    				}
    			}
    L'erreur provient de la 2ème boucle (en gras).
    merci

  2. #2
    Membre chevronné Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Points : 2 232
    Points
    2 232
    Par défaut
    En fait le problème vient du fait que tu parcours une fois le resultset rs puis tu essaye de le reparcourir alors que tu es encore en bas.
    Pour pouvoir "remonter" en haut de ton resultSet il faut créer le Statement ainsi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);;
    ensuite à la fin de ta boucle tu peux faire un
    pour remonter en haut de ton ResultSet.
    autant l'hiver éclate que l'hétéroclite
    le vrai geek c'est celui qui croit qu'il y a 1024 mètres dans un kilomètre

  3. #3
    Membre averti Avatar de mouss4rs
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    884
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 884
    Points : 355
    Points
    355
    Par défaut
    Oui, alors en faite c'est pas ca.
    j'ai trouvé que je n'utilisait pas le meme ResultSet dans les 2 boucles ( une erreur de ma part).

    Maintenant, le probleme c'est que je ne sais pas pourquoi ma classe est Parcouru 3 fois ce qui est trés étrange.
    Je m'explique :

    Voici ma classe qui me permet d'afficher toutes courbes des patients qui ont des mesures en utilisant JFreechart.
    Le probleme c'est que je me suis rendu compte avec un syso qu'il s'affichait 3 fois ce qui fait que je ne vois pas mes courbes dans le graphique mais les légendes des noms des patients.

    La question est: Pourquoi ma classe est parcouru 3 fois de suite ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
     
    package vue;
     
    import java.awt.Color;
    import java.awt.Dimension;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
     
    import javax.swing.JPanel;
     
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.data.time.Hour;
    import org.jfree.data.time.RegularTimePeriod;
    import org.jfree.data.time.TimeSeries;
    import org.jfree.data.time.TimeSeriesCollection;
     
    @SuppressWarnings("serial")
    public class GraphiqueEtatPatient extends JPanel{
     
    	private Connection connection;
    	private final String URL = "jdbc:derby://localhost:1527/DiabetoMedical";
    	private final String USER = ";user=user";
    	private final String PWD = ";password=user";
    	private double glycemie=1.80;
    	NumberAxis rangeAxis;
     
    	ChartPanel chartPanel;
    	JPanel p;
    	JFreeChart chart;
     
    	RegularTimePeriod rtp;
     
    	TimeSeriesCollection dataSet = new TimeSeriesCollection();
    	XYPlot plot;
    	Fenetre fen;
    	int hour = 0;
    	int nbreMesure = 0;
    	private String date;
    //	private Double mixtard30, axtrapide;
     
     
    	public GraphiqueEtatPatient(){
    		p = new JPanel();
     
    		// Couleurs des lignes
    		Color COULEURLIGNE1 = Color.black;
    		//Color COULEURLIGNE2 = Color.red;
     
    		// Creation du graphique
    		chart = ChartFactory.createTimeSeriesChart("Taux de glycémie des patients","Période","Taux de glycémie",dataSet,true,true,false);
    		chartPanel = new ChartPanel(chart, true);
    		System.out.println("ici");
    		try {
    			connection = DriverManager.getConnection(URL + USER + PWD);
     
    			int nbreMesure = 0;
    			int day, month, year;
    			// Creation des lignes
    			//TimeSeries mesure_patient = null;
    			//series_ligne_2 = new TimeSeries("Patient 2", Hour.class);
    			dataSet.removeAllSeries();
    			String nom_patient="";
    			Statement stm = connection.createStatement();
    			ResultSet res = stm.executeQuery("SELECT count(ref) FROM patient");
    			int count = 0;
    			while (res.next()){
    				count= res.getInt(1);
    			}
    			System.out.println("count: "+count);
    			int r = 1;
     
    			Statement stmt = connection.createStatement();
    			ResultSet rs = stmt.executeQuery("SELECT mesure.*, ref, nom FROM mesure, patient WHERE id_patient=ref");
    			while (rs.next()){
    					System.out.println("r"+r);
    				//mesure_patient = new TimeSeries(nom_patient, Hour.class);
    				if (rs.getInt(8)==r){
    					nom_patient = (String)rs.getObject(9);
    					System.out.println("nom_patient: "+nom_patient);
    					int id_patient = (int)rs.getInt(7);
    					System.out.println("id_patient: "+id_patient);
    					nbreMesure++;
    					System.out.println("nbreMesure: "+nbreMesure);
     
    					date=(String) rs.getObject(4);
    					glycemie=(Double) rs.getObject(5);
     
    					day = Integer.parseInt(date.substring(0,2));
    					System.out.println("dat: "+day);
    					month = Integer.parseInt(date.substring(3,5));
    					System.out.println("mois: "+month);
    					year = Integer.parseInt(date.substring(6,10));
    					System.out.println("annee: "+year);
    					System.out.println("glycemie: "+glycemie);
     
    					new TimeSeries(nom_patient, Hour.class).setNotify(true);
    					new TimeSeries(nom_patient, Hour.class).add(new Hour(nbreMesure,day,month,year), glycemie);
    				}else{
    						// Ajout des ligne dans le dataset
    						dataSet.addSeries(new TimeSeries(nom_patient, Hour.class));
    						//dataSet.addSeries(series_ligne_2);
    						r++;
    				}
    			}
    			// Ajout des ligne dans le dataset
    			dataSet.addSeries(new TimeSeries(nom_patient, Hour.class));
    			//dataSet.addSeries(series_ligne_2);
    			chart.setNotify(true);
    			chartPanel.setChart(chart);	
    			chartPanel.removeAll();
    			chartPanel.repaint();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		// Les dimensions du graphique
    		Dimension d = new Dimension(350,250);
    		chartPanel.setMaximumSize(d); 
    		chartPanel.setPreferredSize(d); 
    		chartPanel.setMinimumSize(d);
    		p.add(chartPanel);
     
    		plot = (XYPlot) chart.getPlot(); 
    		// On definie une couleur pour les lignes
    		plot.getRenderer().setSeriesPaint(0,COULEURLIGNE1); 
    		//plot.getRenderer().setSeriesPaint(1,COULEURLIGNE2); 
     
    		// On definie une couleur de fond pour le graphique
    		plot.setBackgroundPaint(Color.white);
    		rangeAxis = (NumberAxis) plot.getRangeAxis();
     
    		// On fixe une taille pour l'axe des ordonnées
    		rangeAxis.setUpperBound(5.0);
    		add(p);
     
    		this.setVisible(true);
    	}
    }

Discussions similaires

  1. Réponses: 3
    Dernier message: 05/01/2010, 17h05
  2. Réponses: 7
    Dernier message: 03/03/2009, 15h15
  3. java.sql.SQLException: Le flux de données est déjà fermé
    Par cyberny dans le forum Interfaces de programmation
    Réponses: 2
    Dernier message: 03/03/2009, 14h19
  4. Réponses: 6
    Dernier message: 17/09/2007, 12h50
  5. Réponses: 7
    Dernier message: 11/08/2006, 09h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo