Can't connect to MySQL from Java: NullPointerException inside MySQL driver connection logic
It might be because you're using an older version of the MySQL driver. You should try using the newest version.
To get the newest version, you can check https://mvnrepository.com/artifact/mysql/mysql-connector-java
As of right now, the newest version is 8.0.11. You can download it here or add this to your pom.xml
:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
Update
Upon further investigation, it seems that it's because of a change that was introduced in MySQL 8.0.1
:
The issue you reported is related to the changes introduced in MySQL 8.0.1 wrt the character sets and collations support, with the addition of now being 'utf8mb4' the default char set. Such changes broke the way Connector/J initializes connections.
As you know this was fixed in Connector/J 5.1.41 and I'm sure you already updated your library.
reference
Like mentionned above, an alternative fix to your problem would have been to use the 5.1.41
instead of 5.1.40
.
Sounds like a potential version mismatch or outdated client. When you run it outside the IDE you may be pulling in the wrong version. I'd make sure the client is on the latest version or similar to the version used by the server.