1

I have a web application that should pull data from a localhost database. I am using Severlets and mysql jdbc, eclipseLink. The problem is when I deploy the application it gives me the following error, even though i have created the database connection which works fine and added the latest mysql (8.0.16) jar to the library.

Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 
2.7.0.v20170811-d680af5): 
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for 
jdbc:mysql://localhost:3306/sampledb?zeroDateTimeBehavior=convertToNull
Error Code: 0

I have also done a clean installation of netbeans 8.2 and java and the error still persist. But I am using two different PC and it is the same problem. For some reason i think netbeans has a bug. I am using glassfish as my server which works fine.

Here is a link yo my project structure: https://res.cloudinary.com/dpsotxezr/image/upload/v1557082088/structure_2_migcvz.png

I also get this error when manually trying to connect to mysql server

mysqld: File '.\binlog.index' not found (OS errno 13 - Permission denied)
2019-05-05T18:51:07.133050Z 0 [System] [MY-010116] [Server] C:\Program 
Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.16) starting as 
process 1796
2019-05-05T18:51:09.509588Z 0 [Warning] [MY-010091] [Server] Can't create 
test file C:\Program Files\MySQL\MySQL Server 8.0\data\LAPTOP- 
43BL4A79.lower-test
2019-05-05T18:51:09.510028Z 0 [Warning] [MY-010091] [Server] Can't create 
test file C:\Program Files\MySQL\MySQL Server 8.0\data\LAPTOP- 
43BL4A79.lower-test
2019-05-05T18:51:10.672870Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-05-05T18:51:12.306701Z 0 [System] [MY-010910] [Server] C:\Program 
Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 
8.0.16)  MySQL Community Server - GPL.
  1. So i have added the latest mysql driver to the project library
  2. I have also tried Class.forName("com.mysql.jdbc.Driver"); but still dont work
  3. Glassfish says there is no suitable driver.

PLEASE HELP, I have been trying to fix this problem for over a week now and related problems solutions on this site dont seem help.

jr3000
  • 368
  • 1
  • 3
  • 17
  • *"So i have added the latest mysql driver to the project library"*. This is very ambiguous. How exactly did you do that? Does it correspond to placing the physical JAR file in the `/WEB-INF/lib` folder of the resulting WAR file, or in the `/modules` folder of the GlassFish server installation? Your problem suggests that this is not the case. – BalusC May 05 '19 at 19:09
  • I have added it to the /WEB-INF/lib folder – jr3000 May 05 '19 at 19:13

2 Answers2

1

I see several issues here. First of all, try to connect to your database with a simple program:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

// Notice, do not import com.mysql.cj.jdbc.*
// or you will have problems!

public class LoadDriver {
    public static void main(String[] args) {
        try {
            // The newInstance() call is a work around for some
            // broken Java implementations

            Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
        } catch (Exception ex) {
            // handle the error
        }
    }
}

(copied from https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-connect-drivermanager.html)

As you can see the classname has changed to com.mysql.cj.jdbc.Driver.

Then your attempt to connect manually: you get a permission denied. I haven't used Windows in a long time but maybe you can install MySql into another folder like C:\mysql (see also: https://dev.mysql.com/doc/refman/8.0/en/windows-installation-layout.html)

And then you will run probably into another issue with the latest driver: MySQL JDBC Driver 5.1.33 - Time Zone Issue

And last but not least: if you everything works and you want to update the driver in Glassfish you need to copy the jar to %GLASSFISH%/glassfish/lib

Joachim Rohde
  • 5,915
  • 2
  • 29
  • 46
0

Add this below line into your project before connection

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

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sampledb", "root", "");
shitu
  • 29
  • 4