java 找不到 JDBC 驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5390604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot find JDBC driver
提问by kostas trichas
try
{
String userName = "root";
String password = "";
//<facility> is my database
String url = "jdbc:mysql://localhost/facility";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.out.println ("Cannot connect to database server " +e.getClass().getName());
}
output> Cannot connect to database server java.lang.ClassNotFoundException
输出> 无法连接到数据库服务器 java.lang.ClassNotFoundException
回答by u290629
It seems that you should put your MySQL driver jar into your classpath.
看来您应该将 MySQL 驱动程序 jar 放入classpath 中。
回答by Johann du Toit
To use the MYSQL Driver (Connector/J) you will need to download it from MySQL Connectorsand put it in your classpath.
要使用 MYSQL 驱动程序 (Connector/J),您需要从MySQL Connectors下载它并将其放在您的类路径中。