简体   繁体   中英

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM