调用CallableStatement.execute()时出现问题;

时间:2017-07-24 03:34:22

标签: java stored-procedures jdbc

当我尝试调用执行CallableStatement.execute()时, 我得到以下异常

  

java.sql.SQLException:指定为定义者的用户   ('学生' 127.0.0.1:3306')不存在

myDB URL- :jdbc:mysql://127.0.0.1:3306/demo?useSSL=false
Username- student
password- student

如果我尝试使用语句对象建立连接并执行简单的select语句,则相同的代码可以正常工作。

我还检查了存储过程代码段,它具有相同的定义CREATE DEFINER=学生@ 127.0.0.1:3306``

我附上了我的代码片段,并且有几个图片链接确保了定义器的正确性。

请让我知道我哪里出错了以及如何解决这个问题

代码: [SQL EXCEPTION THROWN] [1] Connection Credentials Stored Procedure Snippet

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();
        }
    }
}

1 个答案:

答案 0 :(得分:1)

关于mysql文档,它指定了CREATE DEFINER

  

应该是指定为' user_name' @' host_name',

的MySQL帐户

Create Stored Procedure Link

一种可能的解决方案是将CREATE DEFINER改为

CREATE DEFINER = 'student'@'127.0.0.1'

CREATE DEFINER = 'student'@'localhost'

CREATE DEFINER = 'student'@'%'

尝试从定义器中删除端口号。