"Unable to find JDBC driver" but the .jar is in the classpath

Windows 10 x64.
java --version:

openjdk 18.0.1.1 2022-04-22
IBM Semeru Runtime Open Edition 18.0.1.1 (build 18.0.1.1+2)
Eclipse OpenJ9 VM 18.0.1.1 (build openj9-0.32.0, JRE 18 Windows 10 amd64-64-Bit Compressed References 20220509_69 (JIT enabled, AOT enabled)

classpath contains directory where mariadb-java-client-3.1.1.jar is, for example:

.;JAVA_HOME\lib;C:\blablabla\JConnector

When starting openfire service log is filled with

“org.jivesoftware.database.DbConnectionManager - Failed to create the connection provider specified by connectionProvider.className. Using the default pool.
java.lang.RuntimeException: Unable to find JDBC driver org.mariadb.jdbc.Driver”

Openfire didn’t check classpath directory for .jar’s?

When putting .jar in openfire\lib directory then this error disappears, but other error starting to spawn:

“org.jivesoftware.database.DbConnectionManager - Socket fail to connect to host:address=(host=localhost)(port=3306)(type=primary). Connection refused: no further information
java.sql.SQLNonTransientConnectionException: Socket fail to connect to host:address=(host=localhost)(port=3306)(type=primary). Connection refused: no further information”

I think this error is the problem or mariadb connector, but maybe no.

Are you sure that the classpath that you’re showing is the classpath as used by Openfire? In any case, placing the library in openfire\lib works (and is the recommended approach).

The error that is logged when you place the library in openfire\lib indicates that there is an issue with the JDBC string that is used to configure the connection from Openfire.

I’m not java-programmer so don’t know how it’s really works, but from what I’ve read and understand is that system’s classpath is shared for all java apps, no?
If no, then it’s very strange that someone must make duplicates of libraries for each application to work. So if I have, for example, 50 java programs, and each of them uses 20 libraries that are placed in system’s classpath then to make it work I need to copy this 20 libraries 50 times? That’s weird. What is the propose of system variable then? Unbelievable.

PS: Previously I’ve placed .jar in openfire’s lib\ folder and it found library ok then I write this report as believe that this is a bug when openfire ignored -common- library path.
And I told it in first message: “When putting .jar in openfire\lib directory then this error disappears, but other error starting to spawn:” and “I think this error is the problem or mariadb connector, but maybe no.”
I don’t know correct url for named pipes in windows, it’s different from mysql’s java url string. I’ve lost two days to find correct url with no luck.

I’ll skip over the frustration-laden comments on classpath logic. If you are looking for support on that from the volunteers that are providing help in this community, then you’re unlikely to motivate people this way.

I’m no MariaDB or Windows expert. I’m not sure if named pipes are supported in MariaDB. A quick Google yields a result that suggests that this is implemented by a plugin. Maybe that’s not enabled by default? You are probably best off looking for answers from the MariaDB community for more details on that.

Pending feedback of that, you could try to use plain old sockets to get a connection from Openfire to your database. The JDBC URL for that is similar to the MySQL one, but uses the jdbc:mariadb namespace, like so:

jdbc:mariadb://localhost:3306/DB?user=root&password=myPassword

guus, I’m using tcp connection to mariadb now, but willing to connect through named pipe because of maximising security. I’ve asked about it at mariadb slack but no answers for now (mariadb site redirects there… very strange but no options).
PS: if you maybe interested a little - link for the auth plugin is not the solution because it’s about authentication/credentials as logged in user but not totally about the connection at all.
It’s the second part of question and not about openfire, so you can ignore because have no information about it. Big thanks for trying to help.

I’ve just asking about ignoring .jar’s in system-wide shared classpath directory by openfire.
From your answer I need to understand that this is java ignores and not openfire?

You should be able to connect to named pipes via the connection string. Whats your connection string look like?

When I’m using mysql then connection string is simple and work perfectly:

  <driver>com.mysql.cj.jdbc.Driver</driver>
  <serverURL>jdbc:mysql:///openfire?protocol=pipe&amp;rewriteBatchedStatements=true</serverURL>

But with mariadb connector any string I’ve tried didn’t work (more than a hundred of combinations tried…)

  <driver>org.mariadb.jdbc.Driver</driver>
  <serverURL>jdbc:mariadb:///openfire?pipe=MySQL&amp;rewriteBatchedStatements=true</serverURL>
  <serverURL>jdbc:mariadb:///openfire?protocol=pipe&amp;rewriteBatchedStatements=true</serverURL>
  <serverURL>jdbc:mariadb:///openfire?pipe=\\\\.\\pipe\\MySQL</serverURL>
  <serverURL>jdbc:mysql:///openfire?permitMysqlScheme&amp;protocol=pipe</serverURL>

Most errors are “hostname must be set” and “the address can’t be null” when some of parameter=value set:

      socket=MySQL&amp;protocol=pipe&amp;namedpipe=true&amp;
      socketPath=MySQL            # hostname must be set
      socketPath=\\.\pipe\MySQL   # hostname must be set
      socketPath=//./pipe/MySQL   # hostname must be set
      pipe=MySQL                  # the address can't be null
      pipe=\\.\pipe\MySQL         # the address can't be null
      pipe=                       # hostname must be set
      protocol=pipe               # hostname must be set

If the mysql driver is working, then its likely the mariadb connector/driver.
I wonder if its as simple as your java version.

That’s what I’ve decided and talk about in first message: “I think this error is the problem or mariadb connector, but maybe no.”
It is broken/buggy or documentation is wrong. :frowning:

I think this is why the maria driver isn’t working.

Installing Dependencies

JNA (net.java.dev.jna:jna) and JNA-PLATFORM (net.java.dev.jna:jna-platform) 4.2.1 or greater are also needed when you would like to connect to the server with Unix sockets or windows pipes.

My machine:

C:\Windows\system32>java -version
openjdk version “18.0.1.1” 2022-04-22
IBM Semeru Runtime Open Edition 18.0.1.1 (build 18.0.1.1+2)
Eclipse OpenJ9 VM 18.0.1.1 (build openj9-0.32.0, JRE 18 Windows 10 amd64-64-Bit Compressed References 20220509_69 (JIT enabled, AOT enabled)
OpenJ9 - 9a84ec34e
OMR - ab24b6666
JCL - 8d05779b116 based on jdk-18.0.1.1+2)

At three VM’s with blank windows where I’ve tested all this too - just only clean win10 x64 and latest java 17 and latest java 18.
At mariadb they told:

Java Version(s) Recommended MariaDB Connector/J Release Series JDBC Version
Java 17, Java 11, Java 8 MariaDB Connector/J 3.0 JDBC 4.2
Java 11, Java 8 MariaDB Connector/J 2.7 JDBC 4.2

and

JNA (net.java.dev.jna:jna) and JNA-PLATFORM (net.java.dev.jna:jna-platform) 4.2.1 or greater are also needed when you would like to connect to the server with Unix sockets or windows pipes.

Is it means that all current java supporting JDBC 4.2 but connector needed 4.2.1?
Misunderstood there.
Because I have latest java RE releases then it supposed to using latest versions of everything including JDBC?

I’ll try to add jna/jna-platform 5.13 (GitHub - java-native-access/jna: Java Native Access) at different locations, including openfire/lib and system-wide classpath later today, we’ll see.
Thank you for pointing this. Read that at the connector page previously but didn’t understand it (that jre connector didn’t includes all needed to make it work out-of-the-box).

Finally I’ve got it.

TLDR; Detailed description:
After I’ve tried about 200 combinations of “host params” and “key-values” in url, read all I’ve found about mariadb-connector-j (first this was about named pipes, later - about everything), forums, github sources etc, I’ve started to learn java (don’t need it at all but was forced by this problem). Write a .java/class that tries to connect to database, run that by "java -cp …: — when using mysql connector — all was ok, when using mariadb — always something went wrong.
Then I tried to connect directly with mariadb’s mysql --user=* --password=* --protocol=PIPE --socket=MySQL — and I’ve got successful connection, this was understandable, because I’ve got successful connection through mariadb-connector-odbc. Returned to java…
Installed IntelliJ IDEA to little speedup this "save, repeat java -cp etc - and tried a ton of parameter combinations and finally got the connection. All was simple. I’ve used url from openfire.xml (&amp;) but url in my .java/.class must be &, only needed parameter is pipe=MySQL (MySQL is the default socket/named-pipe name for a channel, I’ve commented #socket=… in my mariadb.ini).
Finally I’ve got a successfull connection with java connector outside of openfire (before today I’ve always tried to connect by editing openfire.xml’s url and starting/stopping windows service. This was my biggest mistake — I’ve thought that openfire was ok but problem was with mariadb-connector-java (because when url was jdbc:mysql with mysql driver all was ok).
When I’ve got 100% working url (jdbc:mariadb:///openfire?pipe=MySQL) I’ve applied it in openfire.xml and… got a first error — because this is xml (I’ve found it later) all & must be &amp;'s - ok, changed.
Now it is <serverURL>jdbc:mariadb:///openfire?pipe=MySQL&amp;rewriteBatchedStatements=true</serverURL>

Starting service and… openfire didn’t connect.
org.jivesoftware.database.DbConnectionManager - connect: The address can't be null

Next was dances with drums - //./, //localhost/ and so on — result the same “address can’t be null”.

jdbc:mariadb://./openfire?pipe=MySQL&amp;rewriteBatchedStatements=true
jdbc:mariadb://localhost/openfire?pipe=MySQL&amp;rewriteBatchedStatements=true

java/windows classpath is strange for me (I think it’s the bug):
default is CLASSPATH=.;JAVA_HOME\lib
when I’ve added path where my .jar’s are (mariadb/mysql connectors, jna-platform [unneeded totally!], jna) in the way as default written, for example CLASSPATH=.;JAVA_HOME\lib;C:\JAVADIR then java didn’t get this files (checked with sysinternals process monitor). But when I’ve added an asterisk CLASSPATH=.;JAVA_HOME\lib;C:\JAVADIR\* then java successfully read and use .jar’s. So the default JAVA_HOME\lib is not working at all.

When java get jna-5.13.0.jar additionally with mariadb-java-client-3.1.2 (at the moment of this post) connection was successful.

my java code to successfull connection to openfire database:

import java.sql.*;

class MariaDBCon {
    public static void main(String args[]) {
        try {
            Class.forName("org.mariadb.jdbc.Driver");

            Connection con = DriverManager.getConnection("jdbc:mariadb:///openfire?pipe=MySQL","user","password");
// ton of variants:
//            Connection con = DriverManager.getConnection("jdbc:mariadb://address=(host=localhost)(protocol=pipe)(named-pipe=true)(namedpipe=true)(tcpip=0)(socket=MySQL)(path=MySQL)/?protocol=pipe&amp;named-pipe=true&amp;namedpipe=true&amp;tcpip=0&amp;socket=MySQL&amp;path=MySQL","user","password");

            try (Statement stmt = con.createStatement()) {
                stmt.executeQuery("select * from openfire");
            }
            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}