码
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.MysqL.jdbc.JDBC4Connection.MysqL.jdbc.Util.handleNewInstance(Util.java:411)
at com.MysqL.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.MysqL.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at database.DbDemo.main(DbDemo.java:13)
我该怎么做才能解决我的问题?
最佳答案
原文链接:https://www.f2er.com/mysql/433208.html