gpt4 book ai didi

mysql - 用户 "@' localhost' 的访问被拒绝(使用密码 : no)

转载 作者:行者123 更新时间:2023-11-29 11:43:10 24 4
gpt4 key购买 nike

我正在尝试连接到我的数据库,但我的访问被拒绝,请帮助我

String query= "SELECT * FROM id ";
try{

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/xiiip,root,student");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
while (rs.next())
{
int a=rs.getInt("rollno");
String b=rs.getString("name");
int c=rs.getInt("Maths");
int d=rs.getInt("eng");
int e=rs.getInt("ip");
model.addRow(new Object[] {a,b,c});
}

}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) {
JOptionPane.showMessageDialog(this,e.getMessage());
}

最佳答案

更改此行

Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/xiiip,root,student");

Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/xiiip'', root,student);

因为 root 是用户名,student 是密码..数据库的名称是xiiip..
引用api文档.. https://docs.oracle.com/javase/7/docs/api/java/sql/DriverManager.html

关于mysql - 用户 "@' localhost' 的访问被拒绝(使用密码 : no),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35423004/

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