2016-12-05 39 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」。繼續。

相關問題