2016-07-30 64 views
1

驱动程序不Foundjava.lang.ClassNotFoundException连接:com.mysql.jdbc.driver我想我的Java Web应用程序与mysql数据库,但得到的错误

我想打通过我的Java Web应用程序和MySQL数据库之间的连接XAMP。 我也添加了外部jar文件,它是mysql-connector-java-6.0.2.jar,但仍然出现此错误。

我已经完成了这段代码。

public static void main(String[] args) 
{ 
    try { 
     Class.forName("com.mysql.jdbc.driver"); 
     System.out.println("Driver has been found.."); 
    } catch (ClassNotFoundException ex) { 
     System.out.println("Driver Not Found"+ex); 
    } 

    String url="jdbc:mysql://localhost/hms"; 
    String user="root"; 
    String password=""; 

    Connection con=null; 

    try { 
     con=DriverManager.getConnection(url, user, password); 
     System.out.println("Driver is successfully loaded."); 
    } catch (SQLException ex) { 
     System.out.println("Something is not good."); 
    } 
} 
+0

的可能的复制[连接Java的MySQL数据库] (http://stackoverflow.com/questions/2839321/connect-java-to-a-mysql-database) –

回答

1

你应该因为因为Java是区分大小写写这个

public static void main(String[] args) 
{ 
    try { 
     Class.forName("com.mysql.jdbc.Driver"); 
     System.out.println("Driver has been found.."); 
    } catch (ClassNotFoundException ex) { 
     System.out.println("Driver Not Found"+ex); 
    } 

    String url="jdbc:mysql://localhost/hms"; 
    String user="root"; 
    String password=""; 

    Connection con=null; 

    try { 
     con=DriverManager.getConnection(url, user, password); 
     System.out.println("Driver is successfully loaded."); 
    } catch (SQLException ex) { 
     System.out.println("Something is not good."); 
    } 
} 
+0

谢谢你,先生,它适合我。 –

2

Java中的类名区分大小写。你需要把握的“d”,在“驱动程序”:

Class.forName("com.mysql.jdbc.Driver"); 
    // Here ----------------------^ 
+1

非常感谢你的先生。 –

相关问题