Insert into table if not exists
Bonjour
je suis entrain de faire une requete insert sql en java swing
Bon j'ai 2 jTextField et je veux quand je les remplir ajouter ces champs à la base de données mais à condition qu'il ne sont pas déjà enregistrés dans la tables
donc j'ai fait cette requete mais elle m'affiche plein d'erreurs:
Code:
1 2 3 4 5 6 7 8 9 10
|
try{
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+db, "root", "mdp");
stmt = conn.createStatement();
stmt.executeUpdate("insert into router (edge01,edge02)\n" +
" Select edge01,edge02 Where not exists(select * from router where edge01='"+jTextField1.getText()+"' and edge02='"+jTextField2.getText()+"')");
} catch (SQLException ex) {
Logger.getLogger(bdd.class.getName()).log(Level.SEVERE, null, ex);
} |
Voilà les erreurs qu'elle me donne:
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Where not exists(select * from router where edge01='fffffffff' and edge02='fffff' at line 2
le fffff sont les champs que j'ai entré dans les zones du texte.
Merci bien