Building Artifacts (.jar files) with Multiple Database Drivers
Hello,
I am trying to build a .jar file for an application that logs into an Oracle database then logs into a MariaDB database to store those data. I built the .jar file following https://www.jetbrains.com/help/idea/compiling-applications.html#package_into_jar.
When I run the .jar file from the IDE, or if I upload the .jar file to a server and run from there, the Oracle connection and code runs fine, but I get a "No suitable driver found for jdbc:mariadb" error on the Maria code portion. The application runs fine "un-jarred" from the IDE, and I have other applications that run as a .jar with only MariaDB as its data connection and they run fine. It's as if my application cannot have two database drivers packaged together.
Is there something I am missing in building the .jar file, or is this a Java code architecture issue?
I am using IntelliJ 2020.1.1, mariadb-java-client-2.4.4.jar, and ojdbc8.jar
Thank you.
Please sign in to leave a comment.
See https://docs.oracle.com/javase/8/docs/api/java/sql/DriverManager.html .
There are 2 conflicting files in the jars:
When you build a single jar file, only one of these files will be present depending on the priority and it will be your default driver.
It may help if you use Class.forName() instead and exclude this file from the jar so that the correct JDBC driver is loaded.
Thank you for the quick response.