3

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.

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140

3 Answers3

2

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.

chris01
  • 10,921
  • 9
  • 54
  • 93
1

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

Community
  • 1
  • 1
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
  • 1
    I'd be very surprised if this is the actual cause, as the driver defaults to port 3306 when none is specified, see also [the documentation](https://github.com/MariaDB/mariadb-connector-j/blob/master/documentation/use-mariadb-connector-j-driver.creole) which makes clear that port is optional – Mark Rotteveel Jan 29 '17 at 14:07
  • mmm, i don't know @MarkRotteveel i suggest this solution and in fact it worked with him, or maybe he has another port? – Youcef LAIDANI Jan 29 '17 at 14:23
  • 1
    Maybe, or their was an unrelated problem (outdated files), and editing the config triggered a rebuild or something else that fixed the problem – Mark Rotteveel Jan 29 '17 at 14:46
  • 1
    ok @MarkRotteveel, so, you find my answer not useful, maybe the OP can share with us how this work with him :) – Youcef LAIDANI Jan 29 '17 at 14:50
  • 2
    I can understand that to the OP it looks like this solved his problem (which is also why I didn't downvote or anything), but - ignoring the possibility of bugs in the MariaDB Connector/J - there is no way this can be what actually fixed it. – Mark Rotteveel Jan 29 '17 at 15:00
-1

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