This is my code :
triggerBuilder.append(\"DROP TRIGGER IF EXISTS `insert_associated_inquiry`; \");
triggerBuilder.append(\" DELIMITER %% \");
triggerBuilde
Don't use delimiters with JDBC and MySQL. Delimiters are only used by the MySQL console so that it can tell when a trigger, stored procedure, etc that you're typing in has ended. In JDBC, you put the whole SQL string together and then send it to the database. Because you're in control of when the SQL gets sent to the database, there's no need to use delimiters.
I removed the two DELIMITER
lines and the use of the %%
delimiter from your code, and sent the DROP TRIGGER
command to the database separately. The code I was left with is as follows:
con.createStatement().execute("DROP TRIGGER IF EXISTS `insert_associated_inquiry`");
triggerBuilder.append(" CREATE TRIGGER insert_associated_inquiry BEFORE UPDATE ON inquiry ");
triggerBuilder.append(" FOR EACH ROW Begin ");
triggerBuilder.append(" insert into associated_inquiries(inquiry_id , subject , content , inquiry_date , preferred_date ) " );
triggerBuilder.append("values");
triggerBuilder.append(" ( " );
triggerBuilder.append(" OLD.id , ");
triggerBuilder.append(" OLD.subject , " );
triggerBuilder.append(" OLD.content , " );
triggerBuilder.append(" OLD.created_on , " );
triggerBuilder.append(" OLD.preffered_date " );
triggerBuilder.append(" ) ; ");
triggerBuilder.append(" END ");
con.createStatement().execute(triggerBuilder.toString());
This code appeared to work, in that I could run this code without error regardless of whether the trigger already existed. If the trigger did not previously exist it was created.
the reason is because "delimiter " is not part of the standard of mysql, just remove the delimiter sentence and you code should work.