[英]java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse even though the mysql-connector jar is referenced
I know this has been asked before, but in my case, adding the library (Rightclickling project>Buildpath>Configure buildpath>Add External JARs> Select JAR) hasn't worked and I still keep receiving the error. 我知道以前曾有人问过这个问题,但就我而言,添加库(Rightclickling项目> Buildpath>配置构建路径>添加外部JAR>选择JAR)一直没有奏效,但我仍然继续收到该错误。
Here's my code: 这是我的代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Client {
public static void main(String[] args) throws Exception
{
getConnection();
}
public static Connection getConnection() throws Exception
{
try
{
String driver = "com.mysql.jbdc.Driver";
String url = "jdbc:mysql://localhost:3306/testdb";
String username = "root";
String password = "admin";
Class.forName(driver);
//Creating a variable for the connection called "con"
Connection con = DriverManager.getConnection(url, username, password);
System.out.println("Connected");
return con;
} catch(Exception e){System.out.println(e);}
return null;
}
}
And "mysql-connector-java-52.40-bin.jar" appears under "Referenced Libraries". 并且“ mysql-connector-java-52.40-bin.jar”出现在“参考库”下。
Any help would be appreciated. 任何帮助,将不胜感激。
Nevermind, I'm an idiot. 没关系,我是个白痴。 It has to be "jdbc" instead of "jbdc".
它必须是“ jdbc”而不是“ jbdc”。 Carry on.
继续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.