0

After googling a lot and seeing the answers here on SO of similar questions, I am still getting this error of ClassNotFoundException.

I tried the method here and here.

My apache tomcat webapps directory is C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps. I also uploaded the mysql-connector-java-5.1.22-bin.jar file in C:\Program Files\Java\jre7\lib as mentioned in some of answers here in SO.

In my webapps/jsp folder I created an index.jsp file but it shows an error in the line Class.forName("com.mysql.jdbc.Driver").newInstance();

My current folder structure is:

     C:\
        -> Program Files
            -> Apache Software Foundation 
                ->  Tomcat 6.0
                    -> webapps
                         -> jsp
                             -> index.jsp
                             -> WEB-INF
                                 ->  lib
                                     -> mysql-connector-java-5.1.22-bin.jar

Can anyone help me out?

Community
  • 1
  • 1
gopi1410
  • 6,567
  • 9
  • 41
  • 75

2 Answers2

2

Put all of your libraries under this kind of structure :

  C:\
    -> Program Files
        -> Apache Software Foundation 
            ->  Tomcat 6.0
                -> webapps
                     -> Your web application
                         -> WEB-INF
                             ->  lib
                                 -> mysql-connector-java-5.1.22-bin.jar (and all other required jars)

You should include all your libraries inside the lib folder as any classes that your web app requires will be available to it readily from there.

This what servletworld.com says
"... classes and resources in JAR files under the /WEB-INF/lib directory are included in classpath and made visible to the containing web application."

Abubakkar
  • 15,488
  • 8
  • 55
  • 83
-1

You can include the mysql jar file in the web application itself. Include the jar in C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\\WEB-INF\lib\mysql-connector-java-5.1.22-bin.jar

Mayuran
  • 669
  • 2
  • 8
  • 39