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
|
private void btnajouterActionPerformed(java.awt.event.ActionEvent evt) {
String sql="INSERT INTO user(numero,nom,nomsession,motdepasse,codeservice)"
+ "VALUES(?,?,?,?,?) ";
try{
pst=con.prepareStatement(sql);
//Verifie si profil exite déja
boolean b=false;
for(int j=0; j<dt.getRowCount();j++){
if(Integer.parseInt(txtnumero.getText()) ==dt.getValueAt(j, 0)){
b=true;
break;
}
}if (b==false){
pst.setString(1, txtnumero.getText());
pst.setString(2, txtnom.getText());
pst.setString(3, txtnomsession.getText());
pst.setString(4, txtmotdepasse.getText());
pst.setString(5, cmbservice.getSelectedItem().toString());
pst.execute();
AfficherProfil();//Recharge la liste de profils
JOptionPane.showMessageDialog(null, "Profil ajouté avec succès !");
}else{
JOptionPane.showMessageDialog(null, "Ce numero existe déja");
if (JOptionPane.showConfirmDialog(null,"Confirmer la création d'un profil","Confirmation",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
txtnumero.setText("");
txtnom.setText("");
txtnomsession.setText("");
txtmotdepasse.setText("");
this.cmbservice.removeAll();
}
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Erreur Ajout nouveau profil\n"+e.getMessage());
e.printStackTrace();
}
} |
Partager