[clos] bouton

Fermé
dmo83 Messages postés 79 Date d'inscription vendredi 19 août 2011 Statut Membre Dernière intervention 11 octobre 2011 - 26 sept. 2011 à 13:09
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 - 26 sept. 2011 à 19:51
j'arrive a exécuter maintenant,mais je ne réalisé aucune action sur le bouton ajouter et afficher je veux dire que quand j clic sur clic sur le bouton ajouter mes zone de saisie n se vide pas (initialiser)
mon code:
public void jajouter(String jref,String jdesigne,double jprix) throws SQLException, ClassNotFoundException {
/*ResultSet rs=null;*/
Connection conn=null;


String url="jdbc:mysql:/localhost/bd_produit?";

//Class.forName("org.gjt.mm.mysql.Driver");

int resultat;
Statement st=null;
if(conn==null){
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(url);
String requete="insert into produit(ref,designation,prix) values('"+jref+"','"+jdesigne+"',"+jprix+")";
st=conn.createStatement();
resultat=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();
}
}


}


}
initialiser();
}

public void initialiser(){
jref.setText("");
jdesigne.setText("");
jprix.setText("");
}

public void jafficher()throws Exception{
//String requete = "select* from produit";
Connection conn=null;

Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql:/localhost/bd_produit?";

Class.forName("org.gjt.mm.mysql.Driver");
conn=DriverManager.getConnection(url);
ResultSet rs=null;
Statement st=null;
if(conn==null){
try{

String requete = "select* from produit";

st =conn.createStatement();
rs = st.executeQuery(requete);
rs.first();
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();
}
}


}





}


}

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
26 sept. 2011 à 19:51
0
Rejoignez-nous