【发布时间】:2012-08-14 19:36:20
【问题描述】:
我正在寻找一种在 MySQL 中创建函数的方法,最好是通过脚本(从 Java 执行),但标准 JDBC 或 Spring 的 JdbcTemplate 也可以。
我已经成功地使用 mysql 命令行控制台创建了函数:
DELIMITER $$
CREATE FUNCTION test() RETURNS double DETERMINISTIC
BEGIN
RETURN 63;
END$$
但是由于DELIMITER 不是有效的 SQL 语法,所以在从脚本运行它时出现异常:
[42000][1064] 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 $$
当我尝试使用 Spring JDBC 模板创建它时
jdbcTemplate.execute("CREATE FUNCTION some() RETURNS double DETERMINISTIC\n" +
"BEGIN\n" +
"RETURN 63;\n" +
"END;");
我得到以下异常:
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
'CREATE FUNCTION some() RETURNS double DETERMINISTIC
BEGIN
RETURN 63;
END' at line 1`
有人知道怎么做吗?
【问题讨论】:
-
你找到解决办法了吗?
标签: java mysql sql jdbc jdbctemplate