Helio Ortega Neto
Helio Ortega Neto

Reputation: 33

No suitable driver found for jdbc:mariadb (Netbeans)

I'm using the mariadb-java-client-1.5.7.jar connector for MariaDB, and it does not work.

Here's the connection code:

    public DataAccess() throws SQLException, ClassNotFoundException {
        this.driver = "org.mariadb.jdbc.Driver";
        this.host = "jdbc:mariadb://localhost/bluebank";
        this.user = "root";
        this.password = ""; 
        Class.forName(this.driver);
        this.conn = DriverManager.getConnection(this.host, this.user, this.password);
    }

I get:

    java.sql.SQLException: No suitable driver found for jdbc:mariadb://localhost/bluebank
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at DAO.DataAccess.<init>(DataAccess.java:31)

Apart from adding as an external jar to the libraries, I've added it as a driver to the databases in (Services) in Netbeans. Also, if I remove the Class.forName(), it doesn't work as well.

Upvotes: 3

Views: 15377

Answers (3)

nicht_menschlich
nicht_menschlich

Reputation: 9

replace mariadb in the url with mysql:

I had this Problem myself: the solution was quite simple... MariaDB is basically still MySQL. In the Url you are using to connect to the Database (jdbc:mariadb://localhost:3306) you can therefore just use jdbc:mysql://localhost:3306 <- i just replaced mariadb with mysql. It is still running on a mariadb server but it works so dont change it ;)

Still i dont know why none of the other solutions have worked but at least it is a solution

Upvotes: -1

chris01
chris01

Reputation: 12427

Had something similar today. Worked in Eclipse, did not with pure Java.

For me it was important to have

Class.forName ("org.mariadb.jdbc.Driver");

to make it work everywhere.

Upvotes: 2

Youcef LAIDANI
Youcef LAIDANI

Reputation: 60046

You forgot the port number of your database :

this.host = "jdbc:mariadb://localhost:port_number/bluebank";

Make sure that your db connector jar, exist in the your jar libraries: https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/

You can learn more here :

Connect to MariaDB from Java application in NetBeans on Linux (Mageia)

Hope this can help you

Upvotes: 1

Related Questions