简体   繁体   English

错误:java.lang.ClassNotFoundException:com.mysql.jdbc.Driver

[英]Error : java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

i am trying to solve this problem by following all steps which is required to connect a Apache Wicket web application to MySQL database. 我试图通过遵循将Apache Wicket Web应用程序连接到MySQL数据库所需的所有步骤来解决此问题。

step1 Right Click on project -> Build Path ->Configure Build Path -> Java Build Path -> Libraries Tab -> Add external jar -> then i browse MySql-Connector-5.0.8 jar file. step1右键单击项目->构建路径->配置构建路径-> Java构建路径->库选项卡->添加外部jar->然后浏览MySql-Connector-5.0.8 jar文件。

step2 In program i write down 第二步:在程序我写下来

public static Connection con=null;
public static Connection getConnection()
{
    try
    {
    Class.forName("com.mysql.jdbc.Driver");     
    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db1", "root", "root");
    }catch(ClassNotFoundException ex){ex.printStackTrace();}
    catch(SQLException e){System.out.println(e);}
    finally{
        try
        {
            con.close();
        }catch(Exception e){}
    }
    return con;
}

but still facing Error the java.lang.ClassNotFoundException: com.mysql.jdbc.Driver now what to do..I need your help 但仍然面临错误java.lang.ClassNotFoundException:com.mysql.jdbc.Driver现在该怎么办..我需要您的帮助

Since you mention your project is a web application I assume that you also use an application server to run your application. 由于您提到的项目是Web应用程序,因此我假设您还使用应用程序服务器来运行应用程序。 Make sure the driver jar is also available to the server. 确保驱动程序jar也可用于服务器。 Depending on the platform you may have to change some of the server's configuration as well. 根据平台的不同,您可能还必须更改某些服务器的配置。

Copy the jar file and paste it into your project. 复制jar文件并将其粘贴到您的项目中。 It will run perfectively. 它将完美运行。

You can fix this error by deploying mysql-connector-java-5.1.25-bin.jar into your application's classpath. 您可以通过将mysql-connector-java-5.1.25-bin.jar部署到应用程序的类路径中来解决此错误。 If you are not sure how to set CLASSPATH, follow instructions given in that article. 如果不确定如何设置CLASSPATH,请按照该文章中的说明进行操作。 Depending upon your build tool you can do following to fix java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse, Maven and Gradle. 根据您的构建工具,您可以执行以下操作来修复java.lang.ClassNotFoundException:Eclipse,Maven和Gradle中的com.mysql.jdbc.Driver。

Read more: http://www.java67.com/2015/07/javalangclassnotfoundexception-com.mysql.jdbc.Driver-solution.html#ixzz5jp43It2X strong text 了解更多: http : //www.java67.com/2015/07/javalangclassnotfoundexception-com.mysql.jdbc.Driver-solution.html#ixzz5jp43It2X 强文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM