Maven/Docker: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/testdb
Hi all,
it's my first post in this forum, so I'm sorry in advance if the issue has been already posted before but I can't find anything similar.
As the title, when I run my docker-compose that pull a simple java application the result is that error
Error de conexion: java.sql.SQLException: No suitable driver found for jdbc:mysql://172.17.0.1:3306/testdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
If I run the application from IntelliJ, I haven't any issue to connect to MySql DB that is a docker container too.
In my pom.xml file I add the mysql connector dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
This is my simple java code where config.getMySqlConnection() is
jdbc:mysql://172.17.0.1:3306/testdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
try
{
// DriverManager: The basic service for managing a set of JDBC drivers.
dbConnection = DriverManager.getConnection(config.getMySqlConnection(), config.getMySqlLogin(), config.getMySqlPassword());
if (dbConnection != null)
{
System.out.println("Connection Successful! Enjoy. Now it's time to push data");
}
else
{
System.out.println("Failed to make connection!");
}
} catch (SQLException e) {
System.out.println("Error de conexion: "+e);
e.printStackTrace();
} catch (Exception e) {
System.out.println("Error desconocido: "+e);
e.printStackTrace();
}
I notice that the jar file has a different MySQL version 8.0.20 instead of 8.0.22. Could be it the problem?
/home/mymachine/IdeaProjects/projectname/lib/mysql-connector-java-8.0.20.jar
Any suggestions it will appreciate, because I can't find the solution.
Best Regards!
Please sign in to leave a comment.
I forgot to add my plugin configuration of Maven Shade Plugin
I've just found the solution.
There is an error in my docker-file...a stupid error...
version: '2.3'
services:
stationfeeder:
image: projectName/imageName:2.5
container_name: name
mem_limit: 2048m
entrypoint:
- java
- -cp
- /app/resources:/app/classes:/app/libs/* <------ without /* doesn't run!
etc...