Search code examples
javamavenjdbcfirebirdjaybird

No suitable driver found for jdbc in Java 8 with Maven


I have a Maven console application using JDBC and FirebirdSQL and Java 8, according to the specification, there is not need to add the class registration anymore, so the line Class.forName("org.firebirdsql.jdbc.FBDriver"); is commented, but when I run the Project I get the error: No suitable driver found for jdbc:firebirdsql://localhost/database, but if a I uncomment the line it Works fine.

The curious thing if that I use a simple console Project w/o using Maven it works with the line commented as the specification says, so the question is: is there a way to getting working with Maven too commenting the line of the class registration?


Solution

  • It appears you are using an old version of Jaybird (the FirebirdSQL JDBC Driver). Version 2.2 and above implement the JDBC 4.0 spec, which does not require the Class.forName() syntax.

    Thanks to the Java SE Service Provider mechanism included in Mustang, Java developers no longer need to explicitly load JDBC drivers using code like Class.forName() to register a JDBC driver. The DriverManager class takes care of this by automatically locating a suitable driver when the DriverManager.getConnection() method is called.

    So, upgrade your Jaybird JDBC driver (link below) and simply leave out the Class.forName() method. It's legacy, and not needed for JDBC drivers (JDBC version 4.0 and above).

    As per the Jaybird documenation, you should use the following in your POM:

    <groupId>org.firebirdsql.jdbc</groupId>
    <artifactId>jaybird-jdkXX</artifactId>
    <version>2.2.9</version>
    
    • The artifactId depends on your target Java version: jaybird-jdk18, jaybird-jdk17, or jaybird-jdk16

    http://www.firebirdsql.org/en/jdbc-driver/

    http://www.onjava.com/2006/08/02/jjdbc-4-enhancements-in-java-se-6.html