Compilation

dmo83 Messages postés 79 Date d'inscription vendredi 19 août 2011 Statut Membre Dernière intervention 11 octobre 2011 - 17 sept. 2011 à 13:03
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 - 19 sept. 2011 à 09:12
bonjours!jéssaie de compiler mon programme mè il se bloque avant quand j clikè sur run il compile d'abord avant d'executer mè cette foi ci il ni parvient plus ie la compilation ne marche pas il me mets starting Gestion_Produit .jpr j travaille avec jdeveloper 11g et swing pour l'interface que faire?
voici mon code:
package produit;

import java.awt.Dimension;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.List;
import java.awt.Rectangle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//import java.io.*;
//import java.sql.*;
import java.sql.Array;
import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.text.NumberFormat;

//import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
//import javax.swing.JOptionPane;



public class Frm_produit extends JFrame {
private JButton jajouter = new JButton();
private JButton jenregistrer = new JButton();
private JButton jsupprimer = new JButton();
private JButton jafficher = new JButton();
private JButton jfermer = new JButton();
private JTextField jref = new JTextField();
private JTextField jdesigne = new JTextField();
private JTextField jprix = new JTextField();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private Object statement;
private Connection conn;
private JButton jprecedent = new JButton();
private JButton jsuivant = new JButton();
private JButton jfirst = new JButton();
private JButton jlast = new JButton();

public Frm_produit() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
this.getContentPane().setLayout( null );
this.setSize(new Dimension(866, 381));
this.setTitle( "OPERATIONS SUR LES PRODUITS" );
jajouter.setText("AJOUTER");
jajouter.setBounds(new Rectangle(5, 270, 140, 25));
jajouter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ajouter_actionPerformed(e);
}
});
jenregistrer.setText("ENREGISTRER");
jenregistrer.setBounds(new Rectangle(150, 275, 125, 20));
jenregistrer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
enregistrer_actionPerformed(e);
}
});
jsupprimer.setText("SUPPRIMER");
jsupprimer.setBounds(new Rectangle(280, 275, 125, 20));
jsupprimer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
supprimer_actionPerformed(e);
}
});
jafficher.setText("AFFICHER");
jafficher.setBounds(new Rectangle(410, 275, 125, 20));
jafficher.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
afficher_actionPerformed(e);

}
});
jfermer.setText("FERMER");
jfermer.setBounds(new Rectangle(535, 275, 105, 25));
jfermer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fermer_actionPerformed(e);
}
});
jref.setBounds(new Rectangle(165, 20, 170, 20));
jref.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ref_actionPerformed(e);
}
});
jdesigne.setBounds(new Rectangle(160, 75, 350, 20));
jdesigne.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
designation_actionPerformed(e);
}
});
jprix.setBounds(new Rectangle(160, 130, 180, 20));
jprix.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
prix_actionPerformed(e);

}
});
jLabel1.setText("REFERENCE");
jLabel1.setBounds(new Rectangle(5, 20, 140, 20));
jLabel1.setFont(new Font("Tahoma", 1, 18));
jLabel2.setText("DESIGNATION");
jLabel2.setBounds(new Rectangle(5, 75, 150, 20));
jLabel2.setFont(new Font("Tahoma", 1, 18));
jLabel3.setText("PRIX");
jLabel3.setBounds(new Rectangle(10, 135, 60, 15));
jLabel3.setFont(new Font("Tahoma", 1, 18));
jprecedent.setText("precedent");
jprecedent.setBounds(new Rectangle(110, 325, 115, 25));
jsuivant.setText("next");
jsuivant.setBounds(new Rectangle(230, 325, 60, 25));
jfirst.setText("FIRST");
jfirst.setBounds(new Rectangle(35, 330, 65, 20));
jlast.setText("LAST");
jlast.setBounds(new Rectangle(300, 330, 70, 20));
this.getContentPane().add(jlast, null);
this.getContentPane().add(jfirst, null);
this.getContentPane().add(jsuivant, null);
this.getContentPane().add(jprecedent, null);
this.getContentPane().add(jLabel3, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jprix, null);
this.getContentPane().add(jdesigne, null);
this.getContentPane().add(jref, null);
//connexion base de données

this.getContentPane().add(jfermer, null);
this.getContentPane().add(jafficher, null);
this.getContentPane().add(jsupprimer, null);
this.getContentPane().add(jenregistrer, null);
this.getContentPane().add(jajouter, null);
Connection conn=null;

Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql:/127.0.0.1/BD_PRODUIT?user=root";
// Class.forName("org.gjt.mm.mysql.Driver");
conn=DriverManager.getConnection(url);


}



//saisir un nouveau produit
public void jajouter(String jref,String jdesigne,double jprix) throws SQLException, ClassNotFoundException {
ResultSet rs=null;
Statement st=null;
if(conn==null){
try{

String requete="insert into produit(ref,designation,prix) values('"+jref+"','"+jdesigne+"',"+jprix+")";
st=conn.createStatement();
rs=st.executeUpdate(requete);
}
catch(SQLException ex){
JOptionPane.showInternalConfirmDialog(null,"sql incorrecte","Erreur",JOptionPane.ERROR_MESSAGE);
}
finally{
if(st!=null){
try{
st.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(rs!=null){
try{
rs.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(conn!=null){
try{
conn.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}


}


}

}
//affiche tous les produits enregistres dan la table produit
public void jafficher()throws Exception{
//String requete = "select* from produit";

ResultSet rs=null;
Statement st=null;
if(conn==null){
try{

String requete = "select* from produit";

st =conn.createStatement();
rs = st.executeQuery(requete);

while(rs.next()){

System.out.println(rs.getString("jref") +" "+rs.getString("designation")+" "+rs.getString("jprix"));

}
//rs.close();

}
catch(SQLException ex){
JOptionPane.showMessageDialog(null,"anomalie lors de l'execution de la requete","Erreur",JOptionPane.ERROR_MESSAGE);
}
finally{
if(st!=null){
try{
st.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(rs!=null){
try{
rs.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(conn!=null){
try{
conn.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}


}





}


}
//supprimer un enregistrement
public void jsupprimer(String jref)throws Exception{

//if(JOptionPane.showConfirmDialog(this, "voulez vous supprimer cet enregistrement", "Supprimer", 0)==0){

ResultSet rs=null;
Statement st=null;

if(conn==null){
try{

String requete="delete from produit where ref='"+jref+"' ";
st =conn.createStatement();
rs = st.executeUpdate(requete);
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null,"anomalie lors de l'execution de la requete","Erreur",JOptionPane.ERROR_MESSAGE);
}

finally{
if(st!=null){
try{
st.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(rs!=null){
try{
rs.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(conn!=null){
try{
conn.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}


}

}

//}
}
//affiche l'enregistrement precedent
public void jprecedent()throws Exception{
ResultSet rs=null;
Statement st=null;
if(conn==null){
try{

String requete="select * from produit";
st= conn.createStatement();
rs=st.executeQuery(requete);
//rs.afterLast();

while(rs.previous()){

System.out.println(rs.getString("ref") +""+rs.getString("designation")+""+rs.getString("prix"));
}
rs.close();
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null,"anomalie lors de l'execution de la requete","Erreur",JOptionPane.ERROR_MESSAGE);
}

finally{
if(st!=null){
try{
st.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(rs!=null){
try{
rs.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(conn!=null){
try{
conn.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}


}
}
}
//affiche l'enregistrement suivant
public void jsuivant()throws Exception{
ResultSet rs=null;
Statement st=null;
if(conn==null){
try{

String requete="select* from produit";
st=conn.createStatement();
rs=st.executeQuery(requete);
while(rs.next()){

System.out.println(rs.getString("ref") +""+rs.getString("designation")+""+rs.getString("prix"));

}
//rs.close();
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null,"anomalie lors de l'execution de la requete","Erreur",JOptionPane.ERROR_MESSAGE);
}

finally{
if(st!=null){
try{
st.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(rs!=null){
try{
rs.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(conn!=null){
try{
conn.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}


}

}
}
//affiche le premier enregistrement
public void jfirst()throws Exception{
ResultSet rs=null;
Statement st=null;
if(conn==null){
try{

String requete="select* from produit";
st=conn.createStatement();
rs=st.executeQuery(requete);

while(rs.first()){
System.out.println(rs.getString("ref") +""+rs.getString("designation")+""+rs.getString("prix"));
}

}
catch(SQLException ex){
JOptionPane.showMessageDialog(null,"anomalie lors de l'execution de la requete","Erreur",JOptionPane.ERROR_MESSAGE);
}

finally{
if(st!=null){
try{
st.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(rs!=null){
try{
rs.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(conn!=null){
try{
conn.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}


}

}
}
//affiche le dernier enregistrement
public void jlast()throws Exception{
ResultSet rs=null;
Statement st=null;
if(conn==null){
try{

String requete="select* from produit";
st=conn.createStatement();
rs=st.executeQuery(requete);

while(rs.last()){
System.out.println(rs.getString("ref") +""+rs.getString("designation")+""+rs.getString("prix"));
}

}
catch(SQLException ex){
JOptionPane.showMessageDialog(null,"anomalie lors de l'execution de la requete","Erreur",JOptionPane.ERROR_MESSAGE);
}

finally{
if(st!=null){
try{
st.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(rs!=null){
try{
rs.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
if(conn!=null){
try{
conn.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}


}

}

}

private void ajouter_actionPerformed(ActionEvent e) {

}

private void enregistrer_actionPerformed(ActionEvent e) {
if(JOptionPane.showConfirmDialog(this,"voulez-vous enregistrer cet produit?","Enrégistrement du produit",0)==0)
try{
jajouter(jref.getText(),jdesigne.getText(),Double.parseDouble(jprix.getText()));
}

catch(Exception ex){
Logger.getLogger(Frm_produit.class.getName()).log(Level.SEVERE,null,ex);

}
}
private void afficher_actionPerformed(ActionEvent e) {


}

private void fermer_actionPerformed(ActionEvent e) {
System.exit(0);
}

private void ref_actionPerformed(ActionEvent e) {
}

private void designation_actionPerformed(ActionEvent e) {
}
//oblige a saisir des chiffre
private void prix_actionPerformed(ActionEvent e) {
try{
double prix=Double.parseDouble(jprix.getText().trim());
System.out.println(jprix.getText());
}
catch(NumberFormatException ne){
JOptionPane.showMessageDialog(null, "Veuillez saisir des chiffres", "saisir chiffre", JOptionPane.ERROR_MESSAGE);
}
}


public static void main(String[] arg){
EventQueue.invokeLater(new Runnable(){
public void run(){
new Frm_produit().setVisible(true);

}
});

}

//variable de déclarion

private void supprimer_actionPerformed(ActionEvent e) {
}

}



bigboss

1 réponse

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
19 sept. 2011 à 09:12
Bonjour,

Donne nous la trace de ton erreur, indique nous la ligne sur laquelle se situe l'exception et utilises les basiles
[code=java]//Entre ces balises, le code est colorisé
/code Ce sera bien plus facile à lire comme ca.
0
Rejoignez-nous