gpt4 book ai didi

java.sql.SQLException : Access denied for user 'wineship' @'localhost' (using password: YES) 异常

转载 作者:行者123 更新时间:2023-11-28 23:13:22 26 4
gpt4 key购买 nike

我已经搜索了类似的问题来寻找解决我的问题的方法,因为很多人都遇到了与我相同的问题。但是,所有解决方案都没有帮助,我仍然遇到相同的错误堆栈。

这是我启动连接的 java 代码。堆栈清楚地指向 conn=DriverManager.getConnection(...);:

package com.wine.plugins.managers.models;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public abstract class DatabaseModel
{
protected static Connection conn = null;

private static final String url = "jdbc:mysql://localhost/wineships?useSSL=false";
private static final String username = "wineship";
private static final String password = "password";

public DatabaseModel()
{
try {
if(conn == null)
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, username, password);
if (conn != null) {
System.out.println("Connected to the database");
}
}
} catch (SQLException e) {
e.printStackTrace();
System.exit(0);
} catch (InstantiationException e) {
e.printStackTrace();
System.exit(0);
} catch (IllegalAccessException e) {
e.printStackTrace();
System.exit(0);
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(0);
}
}
}

这是堆栈:

[08:24:25 WARN]: java.sql.SQLException: Access denied for user 'wineship'@'localhost' (using password: YES)
[08:24:25 WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
[08:24:25 WARN]: at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
[08:24:25 WARN]: at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
[08:24:25 WARN]: at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:873)
[08:24:25 WARN]: at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1710)
[08:24:25 WARN]: at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
[08:24:25 WARN]: at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2194)
[08:24:25 WARN]: at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2225)
[08:24:25 WARN]: at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2024)
[08:24:25 WARN]: at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
[08:24:25 WARN]: at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
[08:24:25 WARN]: at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[08:24:25 WARN]: at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[08:24:25 WARN]: at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[08:24:25 WARN]: at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[08:24:25 WARN]: at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
[08:24:25 WARN]: at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
[08:24:25 WARN]: at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
[08:24:25 WARN]: at java.sql.DriverManager.getConnection(DriverManager.java:664)
[08:24:25 WARN]: at java.sql.DriverManager.getConnection(DriverManager.java:247)
[08:24:25 WARN]: at com.wine.plugins.managers.models.DatabaseModel.<init>(DatabaseModel.java:21)
[08:24:25 WARN]: at com.wine.plugins.managers.models.ValidBlocksDatabaseModel.<init>(ValidBlocksDatabaseModel.java:10)
[08:24:25 WARN]: at com.wine.plugins.managers.BlockValidityManager.initialize(BlockValidityManager.java:16)
[08:24:25 WARN]: at com.wine.plugins.WineShips.onEnable(WineShips.java:12)
[08:24:25 WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264)
[08:24:25 WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
[08:24:25 WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402)
[08:24:25 WARN]: at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:377)
[08:24:25 WARN]: at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:327)
[08:24:25 WARN]: at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:421)
[08:24:25 WARN]: at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:382)
[08:24:25 WARN]: at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:337)
[08:24:25 WARN]: at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272)
[08:24:25 WARN]: at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544)
[08:24:25 WARN]: at java.lang.Thread.run(Thread.java:748)

MySQL 服务器在 localhost:3306 上运行在 Linux 上的程序 Xampp 上。该代码适用于将从 SQL 服务器请求数据的 Minecraft 服务器。

最佳答案

我一直在修改 phpmyadmin,我发现输入地址而不是使用“%”可以解决我的问题。我还将“localhost”更改为 127.0.0.1 @nigel ren

我的代码现在是:

private static final String url = "jdbc:mysql://127.0.0.1/wineships";
private static final String username = "wineship";
private static final String password = "password";

关于java.sql.SQLException : Access denied for user 'wineship' @'localhost' (using password: YES) 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44972385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com