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 43 44
| public void ajoutterCompte(Compte compte) throws SQLException {
/* Exécution d'une requête de lecture */
PreparedStatement preparedStatement = null;
Connection cnc = null;
String insertTableCompte = "INSERT INTO compte"
+ "(numeroCompte, nom, prenom, identifiant,password, solde) VALUES"
+ "(?,?,?,?,?,?)";
try {
cnc = getConnexionBd();
preparedStatement = cnc.prepareStatement(insertTableCompte);
preparedStatement.setString(1, compte.getNumeroCompte());
preparedStatement.setString(2, compte.getNom());
preparedStatement.setString(3, compte.getPrenom());
preparedStatement.setInt(4, compte.getIdentifiant());
preparedStatement.setString(5, compte.getMotDePasse());
preparedStatement.setDouble(6, compte.getSolde());
// execute insert SQL stetement
preparedStatement.executeUpdate();
System.out.println("le compte a été supprimé");
} catch (SQLException e) {
System.out.println("sql exception : " + e.getMessage());
} finally {
if (preparedStatement != null) {
preparedStatement.close();
}
if (cnc != null) {
cnc.close();
}
}
} |
Partager