这是我的代码:
triggerBuilder.append("DROP TRIGGER IF EXISTS `insert_associated_inquiry`; ");
triggerBuilder.append(" DELIMITER %% ");
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 %% ");
triggerBuilder.append(" DELIMITER ; ");
con.createStatement().execute(triggerBuilder.toString());
这就是抛出的错误:
com.mysql.jdbc.exceptions.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 'DELIMITER %% CREATE TRIGGER insert_associated_inquiry
BEFORE UPDATE ON inquiry ' at line 1
可能是此错误的原因和解决方案。请帮助。谢谢。