Java无法连接到mysql数据库
问题描述:
我想连接一个服务器到一个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搜索了几个小时,但我找不到我的问题的解决方案。这是我用来尝试连接到数据库的整个代码。
答
尝试使用 “mysql的” 替换 “德比”。
答
更换
String source="jdbc:derby://localhost:3306/security";
到
String source="jdbc:mysql://localhost:3306/security";
+0
非常感谢你 –
+0
@EmilGrigore不客气。 – Prabhakaran
非常感谢! –