954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Create trigger mysql5 with java

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);
onsir
Light Poster
38 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

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"

wakydevil1
Newbie Poster
2 posts since Nov 2009
Reputation Points: 10
Solved Threads: 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.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You