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);

Recommended Answers

All 2 Replies

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"

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.