Beginner MySQL, installed mysql8.0.11, excited to connect the database with JDBC, error, tossing for three days still no solution, finally helpless installed a more stable mysql5.5, the problem can be solved, very fascinated, but as long as the error is not happy.
In this record I foolishly insisted on 3 days.
Environment: Win10 + mysql8.0.11 + eclipse
1. Code
1 ImportJava.sql.*;2 3 Public classSqlConnection {4 Private Static FinalString URL = "Jdbc:mysql://127.0.0.1:3306/test?usessl=false&servertimezone=gmt";5 Private Static FinalString NAME = "root";6 Private Static FinalString PASSWORD = "root";7 Public voidthesqlconnection () {8 Try {9Class.forName ("Com.mysql.cj.jdbc.Driver");TenSYSTEM.OUT.PRINTLN ("Connection succeeded"); One}Catch(ClassNotFoundException e) { ASystem.out.println ("Connection Failed"); - e.printstacktrace (); - } theConnection conn =NULL; - Try { -System.out.println ("Get Started"); -conn =drivermanager.getconnection (URL, NAME, PASSWORD); +System.out.println ("Get Success"); -}Catch(SQLException e) { +System.out.println ("Get Failed"); A e.printstacktrace (); at } - if(Conn! =NULL) { - Try { - conn.close (); -}Catch(SQLException e) { - e.printstacktrace (); inconn =NULL; - } to } + } -}
1 Public class MainClass {23 Public Static void Main (string[] args) {4 // TODO auto-generated Method Stub 5 New SqlConnection (). Thesqlconnection (); 6 }78 }
2. Project Structure
Drive package already imported
3. Error messages
Java.sql.SQLException:Access denied for user ' roo ' @ ' localhost ' (using Password:yes)
This error is usually the user name or password is wrong, after several checks the user name and password is correct.
4. Command line can login
5.navicat can also be connected to the
Error occurred at: drivermanager.getconnection (URL, NAME, PASSWORD);
This question is true skin, ask a friend ask seniors ask teacher, can ask all consulted all over, did not solve, heart tired ah.
Finally, uninstall the clean mysql8.0.11, reload the mysql5.5. Rerun the code, the problem is Gone O (* ̄▽ ̄*) o
Java.sql.SQLException:Access denied for user ' roo ' @ ' localhost ' (using Password:yes)