DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Create trigger mysql5 with java (http://www.daniweb.com/forums/thread88376.html)

onsir Sep 3rd, 2007 5:14 am
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);

wakydevil1 Nov 18th, 2009 3:41 pm
Quote:

Originally Posted by onsir (Post 427883)
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"

Ezzaral Nov 18th, 2009 3:50 pm
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.


All times are GMT -4. The time now is 5:33 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC