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:
- Restarted the glassfish server, re-deploy and run the project to test the DB connection
- Removed the mysql-connector*.jar and added it again and performed #1 again, but not successful
- Tried driver Name as "com.mysql.cj.jdbc.driver" but not successful.
- 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);
}
}
}