javajdbcmariadb

Can't connect to Mariadb from Java Netbeans


I'm having a problem connecting my from Java in Netbeans with mariadb in localhost. I've been seeing some post like this Connect to MariaDB from Java application in NetBeans on Linux (Mageia) but doesn't work it's pretty similar so I don't know why this post can't help me.

public BD(String servidor, String database, String usuario, String password) throws SQLException{
    try {


        Class.forName("org.mariadb.jdbc.Driver");
        url="jdbc:mysql://localhost/ddsi";
        conexion=DriverManager.getConnection(url, usuario, password);

        System.out.println("Conexion a Base de Datos "+url+" . . . . .Ok");

    }
    catch (ClassNotFoundException ex) {
        System.out.println(ex);
    }
}

As in the previous link I've tried everything. I also have mariadb library. enter image description here

I checked skip-networking directive in /etc/my.cnf but it is already commented.


Solution

  • You have a sources JAR in your classpath, that won't work. Get a regular JAR mariadb-java-client.jar and put it on the classpath. Better yet use a dependency management tool like gradle or Maven.