当我尝试调用执行CallableStatement.execute()
时,
我收到以下异常
java.sql.SQLException: The user specified as a definer ('student'@'127.0.0.1:3306') does not exist
myDB URL- :jdbc:mysql://127.0.0.1:3306/demo?useSSL=false
Username- student
password- student
如果我尝试建立连接并使用语句对象执行简单的选择语句,则相同的代码可以正常工作。
我还检查了具有相同定义器的存储过程片段CREATE DEFINER=
student@
127.0.0.1:3306``
我附上了我的代码片段和几个图像链接,以确保定义器的正确性。
请让我知道哪里出了问题以及如何解决
代码: [引发 SQL 异常][1]
import java.sql.*;
public class Storedprocedures {
public static void main(String[] args) {
Connection mycon = null;
CallableStatement calstat = null;
PreparedStatement stat = null;
ResultSet rs = null;
String dep = "HR";
int salary = 10000;
try {
// Get a connection to database
mycon = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/demo?useSSL=false", "student", "student");
System.out.println("Conn success");
// Prepare the stored procedure call
calstat = mycon.prepareCall("{call increase_salaries_for_department(?, ?)}");
// Set the parameters
calstat.setString(1, dep);
calstat.setDouble(2, salary);
// Call stored procedure
calstat.execute();
// Prepare statement
stat = mycon.prepareStatement("select * from employees where department=?");
stat.setString(1, dep);
// Execute SQL query
rs = stat.executeQuery();
//Helper Method
RsetIterator.rset(rs);
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
最佳答案
关于 mysql 文档,它指定 CREATE DEFINER
should be a MySQL account specified as 'user_name'@'host_name',
一种可能的解决方案是将 CREATE DEFINER TO 更改为
CREATE DEFINER = 'student'@'127.0.0.1'
或
CREATE DEFINER = 'student'@'localhost'
或
CREATE DEFINER = 'student'@'%'
只需尝试从定义器中删除端口号即可。
关于java - 调用 CallableStatement.execute() 时出现问题;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45272213/