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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| try{
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Ecommerce","root","");
System.out.println("bonne connexion");
String sq="Select nom,prenom from Client";
Statement st =con.createStatement();
ResultSet re =st.executeQuery(sq);
if (re.next())
{
if (re.getString("nom").equals(textnomclient.getText())&&re.getString("prenom").equals(textprenom.getText()))
{
re.close();
st.close();
con.close();
System.out.println("la personne existe ");
}
else
{
String sql="INSERT INTO Client (idclient,nom,prenom,adresse,ville,codepostale,pays,pseudo,password,email)"+
"values("+"NULL,'"+textnomclient.getText()+"','"+textprenom.getText()+"','"+adresse+"','"+ville+"',"+code+
",'"+pays+"','"+pseud+"','"+pass+"','"+mail+"')";
PreparedStatement s =con.prepareStatement(sql);
s.executeUpdate(sql);
s.close();
con.close();
System.out.println("execution ok");
String sqlc ="select idclient from Client where nom="+textnomclient.getText();
Statement sta =con.createStatement();
res= sta.executeQuery(sqlc);
sta.close();
con.close();
System.out.println("transmission ok");
}
}
}catch(SQLException e2)
{
System.out.println( e2.toString());
}
} |
Partager