I am trying to execute a .sql file during the installation of my web project by using jdbc. 2 options suggested from google: either parsing the script manually (by splitting the ";" character) or using ant. I prefer the simple way so ant is a good choice. This is the code i use to set up the database:
public void executeSql(String sqlFilePath) {
final class SqlExecuter extends SQLExec {
public SqlExecuter() {
Project project = new Project();
project.init();
setProject(project);
setTaskType("sql");
setTaskName("SQL Init");
}
}
SqlExecuter executer = new SqlExecuter();
executer.setSrc(new File(sqlFilePath));
executer.setDriver("com.mysql.jdbc.Driver") ;
executer.setPassword("123456");
executer.setUserid("root");
executer.setUrl("jdbc:mysql://localhost:3306/abc");
executer.execute();
}
The code working fine until it meets the part of creating the procedure
DELIMITER //
CREATE PROCEDURE LOG (IN period INT)
BEGIN
INSERT INTO log_archive
SELECT * FROM ablog
WHERE log_date < DATE_SUB(CURRENT_DATE(), INTERVAL period DAY);
DELETE FROM ablog
WHERE log_date < DATE_SUB(CURRENT_DATE(), INTERVAL period DAY);
END//
DELIMITER ;
and give this error:
Caused by: com.mysql.jdbc.exceptions.jdbc4.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 PROCEDURE LOG(IN period INT) BEGIN INSERT INTO log_archi' at line 1
if i remove the stored procedure part, then it will run well. The sql file is also executed succesfully from the mysql command prompt. Do you have any suggestion to solve this problem ?