0

I am developing Restful WebService using NetBeans 8.2, Glassfish 4.1 on my Rhel-7.4 Linux OS, MySQL as my database.
I am unable to load the MySQL driver.

Using the services in NetBeans, I was able to successfully add my SQL driver and test the connection successfully by executing some DB commands.

I created a project and have added mysql-connector-java-8.0.13.jar using the Add Jar in Project properties.

I am getting the error as:

Severe:   java.lang.ClassNotFoundException: com.mysql.cj.jdbc.driver
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1783)
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1633)

Things I have tried:

  1. Restarted the glassfish server, re-deploy and run the project to test the DB connection
  2. Removed the mysql-connector*.jar and added it again and performed #1 again, but not successful
  3. Tried driver Name as "com.mysql.cj.jdbc.driver" but not successful.
  4. I am setting the driver=com.mysql.jdbc.driver in my file.properties file
private void loadDriver() {
   if(!isLoaded){
        logger.info("Loading Driver " + getDriverName()); //"com.mysql.jdbc.driver"
        try {
            Class.forName(getDriverName());
            isLoaded = true;
        } catch (ClassNotFoundException ex) {
            logger.error("Unable to load driver. Add the JDBC Connector jar to the lib folder", ex);
        }
    }
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
mcmattu
  • 101
  • 1
  • 2
  • 5

0 Answers0