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
| private void EnregActionPerformed(java.awt.event.ActionEvent evt) {
try
{
ResultSet rs=null;
int id_arrad=0;
Connection connection;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","");
String sql ="insert into livre values(?,?,?)";
PreparedStatement pst = connection.prepareStatement(sql);
if (ISBN.getText().equals("")){
ISBN.setText("0");
}
pst.setString(1,id_livre.getText());
pst.setString(2,ISBN.getText());
pst.setString(3,libellle.getText().toUpperCase());
int r = pst.executeUpdate();
id_livre.setText("");
ISBN.setText(null);
libelle.setText("");
}
catch (Exception e){
JOptionPane.showMessageDialog(null, "Erreur insertion dans la base de données "+ e.getMessage());
}
} |