Aidez moi "Operation not allowed after ResultSet closed error"

padela007 Messages postés 10 Date d'inscription mercredi 31 mars 2010 Statut Membre Dernière intervention 25 mai 2010 - 22 mai 2010 à 00:52
michaelbeaver1 Messages postés 1 Date d'inscription mercredi 24 juillet 2019 Statut Membre Dernière intervention 24 juillet 2019 - 24 juil. 2019 à 14:42
bonjour, svp aidez moi j'ai un problème dans mon application lors de dernier classe qui affiche le résultat aidez moi car c'est mon PFE et j'ai pas du temps et merci d'avance

c'est le code source de mon classe et lorsque j'exécute mon application et j'arrive à cette étape il m'affiche ce message "Operation not allowed after ResultSet closed"


package package_GUI;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import package_Data_Base.Connection_affiche_tableau;
import package_classes.Table_resultat_scan;
import java.awt.Font;
import java.awt.SystemColor;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Toolkit;
public class Affiche_resulat extends javax.swing.JFrame {
private java.sql.Statement stmt;
private Connection_affiche_tableau mdbc;
public Affiche_resulat() {
setIconImage(Toolkit.getDefaultToolkit().getImage(Affiche_resulat.class.getResource("/package_GUI/images/image.gif")));
mdbc=new Connection_affiche_tableau();
mdbc.init();
Connection conn=mdbc.getMyConnection();
try {
stmt= conn.createStatement();
} catch (SQLException ex) {
ex.printStackTrace();
}

initComponents();
}

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel1.setBackground(SystemColor.scrollbar);
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Le r\u00e9sultat de scannage");
jLabel1.setFont(new Font("Script MT Bold", Font.BOLD, 18));
jLabel1.setForeground(SystemColor.menuText);
jLabel1.setText("Le r\u00e9sultat de scannage");

ResultSet rs=get_resultat();
jTable1.setModel(new Table_resultat_scan(rs));
mdbc.close(rs);
jScrollPane1.setViewportView(jTable1);

jButton1.setText("Retour");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
retour(evt);
}
});

jButton2.setText("Quitter");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
quitter(evt);
}
});

jButton3.setText("Afficher la liste des ports critiques ouverts");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
port_crit_ouvert(evt);
}
});

GroupLayout gl_jPanel1 = new GroupLayout(jPanel1);
gl_jPanel1.setHorizontalGroup(
gl_jPanel1.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_jPanel1.createSequentialGroup()
.addContainerGap(26, Short.MAX_VALUE)
.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 640, GroupLayout.PREFERRED_SIZE)
.addGap(21))
.addGroup(Alignment.LEADING, gl_jPanel1.createSequentialGroup()
.addGap(233)
.addComponent(jLabel1)
.addContainerGap(261, Short.MAX_VALUE))
.addGroup(Alignment.LEADING, gl_jPanel1.createSequentialGroup()
.addGap(129)
.addComponent(jButton3)
.addGap(23)
.addComponent(jButton1)
.addGap(17)
.addComponent(jButton2)
.addContainerGap(151, Short.MAX_VALUE))
);
gl_jPanel1.setVerticalGroup(
gl_jPanel1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_jPanel1.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 522, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
.addGroup(gl_jPanel1.createParallelGroup(Alignment.BASELINE)
.addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE))
.addGap(22))
);
jPanel1.setLayout(gl_jPanel1);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents

private void retour(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_retour
this.setVisible(false);
new Choix_scan().setVisible(true);
}//GEN-LAST:event_retour

private void quitter(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitter
System.exit(0);
}//GEN-LAST:event_quitter

private void port_crit_ouvert(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_port_crit_ouvert
String port_crit[][] = new String[600][600];
String resultat[][] = new String[600][600];
String menace[][] = new String[600][600];

String requete="SELECT * FROM port_critique";
String requete2="SELECT Num_port,Application,Resultat FROM resultat";
String requete3="INSERT INTO menace VALUES(?,?,?,NOW())";
String requete4="SELECT Num_port FROM menace";
String requete5="DELETE FROM menace WHERE Resultat = "fermé"";

Connection_affiche_tableau mdbc5 = new Connection_affiche_tableau();
mdbc5.init();
Connection conn5 = mdbc5.getMyConnection();
Statement stmt5;
try {
stmt5 = conn5.createStatement();
stmt5.executeUpdate(requete5);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}


int h=0;
int m=0;

Connection_affiche_tableau mdbc1=new Connection_affiche_tableau();
mdbc1.init();
Connection conn1=mdbc1.getMyConnection();
Statement rs;
ResultSet res = null;
try {
rs = conn1.createStatement();
res = rs.executeQuery(requete);
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}


Connection_affiche_tableau mdbc2=new Connection_affiche_tableau();
mdbc2.init();
Connection conn2=mdbc2.getMyConnection();
Statement rest = null;
ResultSet resul = null;
try {
rest = conn2.createStatement();
resul= rest.executeQuery(requete2);
} catch (SQLException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}


Connection_affiche_tableau mdbc3=new Connection_affiche_tableau();
mdbc3.init();
Connection conn3=mdbc3.getMyConnection();
Statement rs2;
ResultSet res2 = null;
try {
rs2=conn3.createStatement();
res2= rest.executeQuery(requete4);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


int j=0;
try { while (res.next())
{
port_crit[j][0] = res.getString("Num_portc");

port_crit[j][1] = res.getString("Application");
j++;
}
} catch (SQLException ex) {
ex.printStackTrace();
}
try {



while (resul.next())
{
resultat[h][1] = resul.getString("Num_port");
resultat[h][2] = resul.getString("Application");
resultat[h][3] = resul.getString("Resultat");

h++;
}

} catch (SQLException ex) {
ex.printStackTrace();
}
try {



while (res2.next())
{
menace[m][0] = res2.getString("Num_port");
System.out.println(menace[m][0]);


m++;

}
} catch (SQLException ex) {
ex.printStackTrace();
}
boolean mot1=false;
boolean mot2=false;
boolean mot3=false;
System.out.println(j);

for(int f=0;f<h;f++)
{ int i=0;
int m2=0;
int x3=0;
while(i<j &&( mot1==false || mot2==false))
{
int x1=resultat[f][0].compareTo(port_crit[i][0]);
int x2=resultat[f][3].compareTo("fermé");
/* while(m2<m)
{ x3=resultat[f][0].compareTo(menace[m2][0]);
m2++;}*/
i++;
if(x1==0 )
mot1=true;
if(x2==0)
mot2=true;

}
while(m2<m && mot3==false)
{
x3=resultat[f][0].compareTo(menace[m2][0]);
m2++;
if (x3==0)
mot3=true;}

if(mot1==true && mot2==true && mot3==false)

{

try{
//ConnectionDB_PrepareStatement resutA=new ConnectionDB_PrepareStatement();

Connection conn = mdbc3.getMyConnection();
PreparedStatement instr = conn.prepareStatement(requete3);
instr.clearParameters();
instr.setString(1,resultat[f][0]);
instr.setString(2,resultat[f][1]);
instr.setString(3,port_crit[i-1][1]);
instr.executeUpdate();
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
mot1=false;
mot2=false;
mot3=false;


}
this.setVisible(false);
new Affiche_port_ouvert().setVisible(true);
}//GEN-LAST:event_port_crit_ouvert

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
public ResultSet get_resultat() {

ResultSet rs=null;

try{
rs=stmt.executeQuery("Select * from resultat");

}
catch(SQLException e){}

return rs;

}

}
A voir également:

10 réponses

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 369
22 mai 2010 à 19:20
Ou se trouve ton erreur, quelle ligne, peux tu la mettre en rouge. En gros, tu dois faire appel a une resultSet que tu as fermé. Tu peux tenter avec un try/catch
0