0

Hi,
how to create trigger in mysql 5 with java.
i have code like this, but still error "
java.sql.SQLException: 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 `a1`.`xData` AFTER UPDATE ON `a1`.`tinfo`IF (' at line 1 "
thanks.

SQL="";
 SQL="DELIMITER $$ "+
     "DROP TRIGGER   `a1`.`xData` || "+
     "CREATE TRIGGER `a1`.`xData` AFTER UPDATE ON `a1`.`tinfo`" +
     "FOR EACH ROW BEGIN " +
     "IF (OLD.Name <> NEW.Name) THEN " +
     "INSERT INTO tlog (remark) VALUES ('EditData'); " +
     "END IF; " +
     "END;" +
     "$$" +
     "DELIMITER;";
 stmt=con.createStatement();
 rs=stmt.execute(SQL);
3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Ezzaral
0

Hi,
how to create trigger in mysql 5 with java.
i have code like this, but still error "
java.sql.SQLException: 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 `a1`.`xData` AFTER UPDATE ON `a1`.`tinfo`IF (' at line 1 "
thanks.

SQL="";
 SQL="DELIMITER $$ "+
     "DROP TRIGGER   `a1`.`xData` || "+
     "CREATE TRIGGER `a1`.`xData` AFTER UPDATE ON `a1`.`tinfo`" +
     "FOR EACH ROW BEGIN " +
     "IF (OLD.Name <> NEW.Name) THEN " +
     "INSERT INTO tlog (remark) VALUES ('EditData'); " +
     "END IF; " +
     "END;" +
     "$$" +
     "DELIMITER;";
 stmt=con.createStatement();
 rs=stmt.execute(SQL);

I am having the same problem as well. There doesnt seem to be a lot of stuff on the internet regarding "triggers from Java"

0

That is because it has nothing to do with Java itself. You're just sending a DDL statement to the database. Any difficulties with it would be specific to that database and the JDBC driver.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.