2016-12-05 45 views
0

我知道这已经被问过了,但在我的情况下,添加库(Rightclickling project> Buildpath> Configure buildpath>添加外部JAR>选择JAR)没有工作,我仍然不断收到错误。Eclipse中的java.lang.ClassNotFoundException:com.mysql.jdbc.Driver即使mysql连接器jar被引用

这里是我的代码:

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; 
    } 
} 

和 “使用mysql-connector-java的52.40-bin.jar” 出现在 “引用的库”。

任何帮助,将不胜感激。

+0

将你的完整错误信息添加到你的问题 – Blag

回答

1

没关系,我是个白痴。它必须是“jdbc”而不是“jbdc”。继续。

相关问题