2013-10-26 151 views
0

我想連接一個服務器到一個mysql數據庫。我包含驅動程序庫mysql-connector-java-5.0.8.I安裝了mysql連接器。我有這樣的代碼:Java無法連接到mysql數據庫

public void connect() throws SQLException, ClassNotFoundException{ 

     String source="jdbc:derby://localhost:3306/security"; 
     Class.forName("com.mysql.jdbc.Driver"); 
     Connection con=DriverManager.getConnection(source,"root",""); 

} 我用的是XAMPP爲MySQL database.I了一個叫security.When數據庫中,我嘗試執行connect()方法我收到

 No suitable driver found for jdbc:derby://localhost:3306/security 

exception.I搜索了幾個小時,但我找不到我的問題的解決方案。這是我用來嘗試連接到數據庫的整個代碼。

回答

2

嘗試使用 「mysql的」 替換 「德比」。

+0

非常感謝! –

2

更換

String source="jdbc:derby://localhost:3306/security"; 

String source="jdbc:mysql://localhost:3306/security"; 
+0

非常感謝你 –

+0

@EmilGrigore不客氣。 – Prabhakaran