java.sql.SQLException:用户’root @ localhost’@’localhost’拒绝访问(使用密码:YES)

java.sql.SQLException:用户’root @ localhost’@’localhost’拒绝访问(使用密码:YES),第1张

概述我使用Eclipse和MySQL db连接Java码import java.sql.*; import java.io.*; public class DbDemo { public static void main(String args[]) throws ClassNotFoundException, SQLException {

我使用Eclipse和MySQL db连接Java

import java.sql.*;import java.io.*;public class DbDemo {    public static voID main(String args[]) throws ClassNotFoundException,sqlException {        String s;               String uname="root@localhost";        String url="jdbc:MysqL://localhost:3306/student";        String password="Hsun123";        int i;        try {            Class.forname("com.MysqL.jdbc.Driver").newInstance();            Connection con=DriverManager.getConnection(url,uname,password);            Statement st=con.createStatement();            ResultSet rs=st.executequery("select * from student_detail");            if(rs.next()) {                i=rs.getInt(1);                s=rs.getString(2);                System.out.println(i+"/t"+s);            }                       rs.close();            st.close();            con.close();        } catch(Exception e) {            e.printstacktrace();        }    }}

错误

java.sql.sqlException: Access denIEd for user 'root@localhost'@'localhost' (using password: YES)at com.MysqL.jdbc.sqlError.createsqlException(sqlError.java:1073)at com.MysqL.jdbc.MysqLIO.checkerrorPacket(MysqLIO.java:3597)at com.MysqL.jdbc.MysqLIO.checkerrorPacket(MysqLIO.java:3529)at com.MysqL.jdbc.MysqLIO.checkerrorPacket(MysqLIO.java:935)at com.MysqL.jdbc.MysqLIO.secureAuth411(MysqLIO.java:4101)at com.MysqL.jdbc.MysqLIO.doHandshake(MysqLIO.java:1300)at com.MysqL.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2337)at com.MysqL.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)at com.MysqL.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)at com.MysqL.jdbc.ConnectionImpl.

我该怎么做才能解决我的问题?最佳答案而不是使用:

 String uname="root@localhost";

使用 :

String url="jdbc:MysqL://localhost:3306/student";String username="root"String password="Hsun123"...try{        Class.forname("com.MysqL.jdbc.Driver").newInstance();        Connection con=DriverManager.getConnection(url,username,password);...

这应该工作(假设你设置了有效的密码) 总结

以上是内存溢出为你收集整理的java.sql.SQLException:用户’root @ localhost’@’localhost’拒绝访问(使用密码:YES)全部内容,希望文章能够帮你解决java.sql.SQLException:用户’root @ localhost’@’localhost’拒绝访问(使用密码:YES)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1168328.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)