Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registered driver with driverClassName=org.gjt.mm.mysql.Driver was not found

I'm developing a project and using a spring. It works correctly, but when I added a database to it, I got some exceptions.

WARN com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=org.gjt.mm.mysql.Driver was not found, trying direct instantiation.
ERROR com.zaxxer.hikari.pool.HikariPool        : root - Exception during pool initialization.

java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) ~[mysql-connector-java-5.1.46.jar:5.1.46]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976) ~[mysql-connector-java-5.1.46.jar:5.1.46]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912) ~[mysql-connector-java-5.1.46.jar:5.1.46]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) ~[mysql-connector-java-5.1.46.jar:5.1.46]......

dependencies:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>com.detectlanguage</groupId>
        <artifactId>detectlanguage</artifactId>
        <version>1.1.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.9.1</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>

application.property:

#Database settings
spring.datasource.url=jdbc:mysql://localhost:3306/mSecond
spring.jpa.hibernate.ddl-auto=update
spring.datasource.name=name
spring.datasource.password=password
spring.datasource.driver-class-name=org.gjt.mm.mysql.Driver

spring.datasource.tomcat.connection-properties=useUnicode=true;characterEncoding=utf-8;
spring.datasource.sql-script-encoding=UTF-8

The address of the database is correct and working - 100%

Can someone show another method, more correct for database initialization in the spring?

like image 754
Valentyn Hruzytskyi Avatar asked Jun 17 '18 21:06

Valentyn Hruzytskyi


2 Answers

Do not use this since it has been DEPRECATED!

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

Use this instead

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
like image 58
Knight Rider Avatar answered Oct 18 '22 01:10

Knight Rider


If you change your properties file with the following lines it should work:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root

This driver class is fine for mysql and you need to use spring.datasource.username= instead of spring.datasource.name=

I hope this helps you

like image 4
Sven Hakvoort Avatar answered Oct 18 '22 02:10

Sven Hakvoort