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 static void Ajout_Conjoint(String Matricule, String Nom_Conjoint, String Prenom_Conjoint, String Matricule_Conjoint){
Connection con = null;
Statement st = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException cnfe){
System.out.println("La classe com.mysql.jdbc.Driver n'a pas été trouvée");
cnfe.printStackTrace();}
try {
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db?useSSL=false","root","");
st = con.createStatement();
String rq = "INSERT INTO 'conjoint' ( Matricule, Nom_Conjoint, Prenom_Conjoint, Travail_Sur_BP, Matricule_Conjoint ) VALUES ('"+Matricule+"', '"+Nom_Conjoint+"', '"+Prenom_Conjoint+"', '"+Matricule_Conjoint+"');";
//rs = st.executeUpdate("INSERT INTO 'conjoint' ( Matricule, Nom_Conjoint, Prenom_Conjoint, Travail_Sur_BP, Matricule_Conjoint ) VALUES ('"+Matricule+"', '"+Nom_Conjoint+"', '"+Prenom_Conjoint+"', '"+Matricule_Conjoint+"');");
st.executeUpdate(rq);
System.out.println("Insertion du conjoint réussite !!!!");
} catch ( Exception ex ) { ex.printStackTrace(); }
finally{
if(rs != null)
{
System.out.println("Fermeture de l'objet ResultSet.");
try{
rs.close(); }
catch ( SQLException ignore )
{ System.out.println("Resultset ne peut pas être ignoré."); }
}
if(st != null)
{
System.out.println("Fermeture de l'objet Statement.");
try {
st.close(); }
catch ( SQLException ignore ) { }
}
if(con != null)
{
try{ System.out.println( "Fermeture de l'objet Connection." );
con.close(); }
catch ( SQLException ignore ) { }
}
}
} |
Partager