Java – thesql driver jar not being recognized

driverjavajdbcMySQL

I have an token class file in an jar file. The token class files is the class that uses jdbc to retrieve data from the database. However when I call the jar file it does not seem to recoginize the external mysql driver jar file.

The error is pointed to this line
Class.forName(driver);.

I have referenced the mysql driver in the ant build file and every classpath i could think of.

    <mkdir dir="build/server/dist"/>
    <jar destfile="build/server/dist/VNCOverHTTPServer.jar" basedir="build/server/classes">
        <manifest>
            <attribute name="Main-Class" value="jhttpserver.JHttpServer"/>
            <attribute name="Class-path" value="lib/servlet.jar lib/mysql-connector-java-5.1.7-bin.jar config/"/>
        </manifest>
    </jar>

Nothing is working? any help would be appreciated.

thanks

java.lang.ClassNotFoundException: mysql
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:288)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at socksviahttp.server.token.getConnection(token.java:58)
at socksviahttp.server.token.exists(token.java:75)
at socksviahttp.server.ServletSocks.doPost(ServletSocks.java:328)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at jhttpserver.JHttpServerThread.run(JHttpServerThread.java:217)

Best Answer

And the line registering the mysql driver is something along the lines of:

Class.forname("com.mysql.jdbc.Driver");

The class loader error seems to be for an unadorned 'mysql' class, not one referenced by package. You generally only see this error when you're dynamically loading a class without specifying the full class name.

What do you use to load the mysql driver class? if it's a spring config file, then you probably don't have the full class name in the config file.

And I just noticed the lower case 'Class-path'. It's supposed to be 'Class-Path'

Related Topic