2016-10-28 59 views
0

我在使用JDBC連接到數據庫時遇到問題。我在連接出現以下錯誤:CLIENT_PLUGIN_AUTH is required使用Maven JDBC連接錯誤

這裏是我的代碼:

private void connect() { 
    try { 
    connection = DriverManager.getConnection("jdbc:mysql://"+url+":"+port+"/"+database, username, password); 
    System.out.println(Messages.MYSQL_CONNECT_SUCCESS.toString()); 
    } 
    catch(Exception e) { 
    System.out.println(Messages.MYSQL_CONNECT_FAIL.toString()+e.getMessage()); 
    } 
} 

是我的連接字符串錯了嗎?這是我加入到我的Maven依賴:

<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>6.0.5</version> 
</dependency> 

我用在另一個項目中不使用Maven代碼(不同的消息),並能正常工作。證書工作。我試圖添加Class.forName("com.mysql.jdbc.Driver");,但它不會改變結果。

+1

這可能是由版本「6.0.5」引起的,它仍然有幾個顛簸q.v.這裏:http://stackoverflow.com/questions/37348572/new-mysql-driver-causes-java-sql-sqlnontransientconnectionexception-client-plug –

+0

@TimBiegeleisen你推薦哪個版本呢? – Arraying

+0

請嘗試遵循我在接受的答案中說的鏈接。如果這不能解決問題,那麼請提及這一點,也許別人有另一種解決方案。 –

回答

1

與以下替換您的網址,並嘗試

jdbc:mysql://"+url+":"+port+"/"+database?autoReconnect=true&useSSL=false, username, password 

這是關係到SSL。