我正在使用MySQL数据库并编写了一些程序。如果我尝试使用spring jdbc创建这些过程,我会收到这些过程已经存在的错误消息。如果我用DriverManager连接旧的方式创建一个PreparedStatement并执行它一切正常。 有谁知道为什么会这样?
这里是我正在做的代码
...
connection = new JdbcTemplate(dataSource);
...
for(String sql: sqlScript.split( "(;)" ) ){
connection.execute(sql.trim());
}
这导致SQL-Exception我作为参数提供的过程已经存在。但是,如果我将上述代码片段与此交换:
for(final String sql: sqlScript.split( "(;/)" ) ) {
if (sql.trim().length() > 0)
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?"
+ "user=root" );
PreparedStatement ps =
conn.prepareCall(sql);
ps.execute();
} catch (SQLException e) {
e.printStackTrace();
}
}
一切正常......
如果有人知道这里的错误会不会很好......
至少有一个已存在的程序......甚至可能在您的数据库中......
create procedure insertUser(
in p_firstname varchar(50),
in p_lastname varchar(50),
in p_username varchar(25)
)
begin
declare l_username varchar(25);
select username into l_username
from movielist.user where username = p_username;
if l_username is null then
insert into movielist.User (firstname, lastname, username) values
(p_firstname, p_lastname, p_username);
end if;
end;/