gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 06:35:24 25 4
gpt4 key购买 nike

当我尝试调用执行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] 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();
}
}
}

最佳答案

关于 mysql 文档,它指定 CREATE DEFINER

should be a MySQL account specified as 'user_name'@'host_name',

Create Stored Procedure Link

一种可能的解决方案是将 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/

25 4 0
文章推荐: java - 停止 Java 迭代的条件
文章推荐: javascript - 使用 Backbone.js w/Require.js 的站点在 IE8 中的错误
文章推荐: java - 我在哪里可以找到 java 中已弃用项目的替代品?
文章推荐: php - 如何将 PHP 返回的输出插入到 HTML
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com