【问题标题】:Issue in calling the CallableStatement.execute();调用 CallableStatement.execute() 时出现问题;
【发布时间】:2017-12-29 13:04:54
【问题描述】:

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

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

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

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

我还检查了存储过程 sn-p 它具有相同的定义器CREATE DEFINER=student@127.0.0.1:3306``

我附上了我的 sn-p 和几个图片链接,以确保定义器的正确性。

请告诉我哪里出了问题以及如何解决这个问题

代码: [抛出 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();
        }
    }
}

【问题讨论】:

    标签: java stored-procedures jdbc


    【解决方案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'@'%'
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-16
      • 2019-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2020-12-19
      • 1970-01-01
      相关资源
      最近更新 更多