Я хочу, чтобы сделать INSERT в таблице IF NOT EXISTSВставить, если не существует в таблице
Так что у меня 2 JTextField
с и я хочу добавить переменные, которые я СТГ в JTextfield
сек Int таблицы, но в условии, что они не являются существует в таблице
Это код, и это дает мне ошибки о запросе:
try{
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+db, "root", "123456");
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);
}
Ошибка:
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
Вы уже получили ответ на свой вопрос здесь: http://stackoverflow.com/a/17219357/1065197 IMO я бы выбрал последнее. –