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

來源:互聯網
上載者:User

標籤:資料庫   imp   amp   資料   void   nal   The   比較   manager   

初學mysql,安裝了mysql8.0.11,激動的用jdbc串連資料庫,出現error,折騰了三天依舊無解,最後無奈裝了比較穩定的mysql5.5,問題得以解決,很迷,但只要error沒了就開心。

在此記錄我傻傻堅持的3天。

環境:win10  +  mysql8.0.11 +  eclipse

1.代碼

 1 import java.sql.*; 2  3 public class SqlConnection { 4     private static final String URL = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false&serverTimezone=GMT"; 5     private static final String NAME = "root"; 6     private static final String PASSWORD = "root"; 7     public void TheSqlConnection() { 8         try { 9             Class.forName("com.mysql.cj.jdbc.Driver");10             System.out.println("串連成功");11         } catch (ClassNotFoundException e) {12             System.out.println("串連失敗");13             e.printStackTrace();14         }15         Connection conn = null;16         try {17             System.out.println("開始擷取");18             conn = DriverManager.getConnection(URL, NAME, PASSWORD);19             System.out.println("擷取成功");20         } catch (SQLException e) {21             System.out.println("擷取失敗");22             e.printStackTrace();23         }24         if (conn != null) {25             try {26                 conn.close();27             } catch (SQLException e) {28                 e.printStackTrace();29                 conn = null;30             }31         }32     }33 }
1 public class MainClass {2 3     public static void main(String[] args) {4         // TODO Auto-generated method stub5         new SqlConnection().TheSqlConnection();6     }7 8 }

2.項目結構

已經匯入驅動包

3.錯誤資訊

java.sql.SQLException: Access denied for user ‘roo‘@‘localhost‘ (using password: YES)

出現這個錯誤一般就是使用者名稱或者密碼錯誤了,經多次檢查使用者名稱和密碼正確。

4.命令列可以登陸

5.navicat也可以串連上

錯誤發生處:DriverManager.getConnection(URL, NAME, PASSWORD);

 

這個問題是真的皮,問朋友問學長問老師,能問的都請教了遍,都沒解決,心累啊。

最後的最後,卸載乾淨mysql8.0.11,重裝上mysql5.5.重新運行代碼,問題沒了o(* ̄▽ ̄*)o

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.