java, class not found exception com.mysql.jdbc.Dri

2019-07-10 17:25发布

问题:

This question already has an answer here:

  • Connect Java to a MySQL database 13 answers

I am trying to create the run the following in java program, but i am getting this error.

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source)

    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

in build path, i have added the mysql connector jar file

回答1:

In Eclipse, right-click on the project and select Build Path -> Configure Build Path. Select the Libraries tab, then the Add Jars button. Then select the MySQL jar file as shown in your project. Then press OK then OK. It should now work.