23

I am trying to connect LibreOffice Base with an MySQL database, in phpMyAdmin, with a JDBC-connection.

The first step is to select which database you want to select: Step 1

The second step is to select which connection: Step 2

The third step is to select your database: Step 3

When I press 'Klasse testen' ( Test Class ), I get the following error: 'com.mysql.jdbc.driver cannot be loaded'.

Does anyone know how to avoid this error?

2
  • In the first screen where you chose to Connect, (rather than create or open), you can also select "JDBC" rather than "MySQL". Or in 2rd screen I can now (after I installed teh JDBC connector) "Connect directly". So there appear to be a few ways to get to JDBC. I'm not sure what the difference is, just that this is sort of complicated. Commented Oct 8, 2016 at 15:15
  • @Elipticalview Thanks for mentioning :)
    – M Zeinstra
    Commented Oct 11, 2016 at 11:38

5 Answers 5

48

You need to download and "register" the JDBC connector first. To do so:

  1. Go to http://dev.mysql.com/downloads/connector/j/ and download the ZIP archive with the JDBC connector ("Platform-Independent"); you may alternatively download the MSI installer; in this case, the jar file can be found in Program Files (x86)/MySQL/MySQL Connector J/ (assuming a Win 7 64bit system)

  2. Unzip the archive on your local PC (remember the path to its contents), or alternatively install the MSI file;

  3. In the extracted folder structure, there's a file "mysql-connector-java-5.0.8-bin.jar" (name depends on the exact version you've downloaded)

  4. Run LibreOffice (not Base, just LO);

  5. Open Menu Tools -> Options -> LibreOffice -> Advanced -> Class Path;

    enter image description here

  6. Click Add Archive;

    enter image description here

  7. Select the jar file from step 1-3 and hit OK. Now, the Class Pathdialog should look as follows:

    enter image description here

That's it. Now, LO knows where to look for the MySQL JDBC Driver.

2
  • 5
    For Ubuntu users, you can sudo apt-get install libmysql-java and then set the classpath to /usr/share/java/mysql.jar You can verify the path of the jar file with dpkg -L libmysql-java Note too: you can access Tools -> Options -> Advanced from any LO application e.g. Writer or Calc in order to add the new class path Commented Jun 16, 2017 at 2:38
  • 1
    you can open options from base app as well :-)
    – sbharti
    Commented May 25, 2018 at 10:16
7

BTW, for Mariadb everything else is the same, but the jdbc driver class changes to this:

org.mariadb.jdbc.Driver
2
  • @Wilcar, you must have /usr/share/java/mariadb-java-client-2.2.6.jar (or newer) and set user ownership & -rw-r----- perms. Also in LO Options LibreOffice Advanced open Class Path... and point it to this file, i.e. Add Archive... . BTW, you can open this jar w/ archive manager and drill down to find Driver.class in it, i.e. ..org/mariadb/jdbc/Driver.class Commented Mar 10, 2019 at 2:21
  • Ok, finally it works for me. I used mariadb-java-client-2.4.0.jar and not mariadb-java-client-2.4.0-javadoc.jar
    – Wilcar
    Commented Mar 10, 2019 at 6:38
4

If you're using Red Hat like linux distros like Fedora, you can install it from the repositories with yum or dnf and then:

In Base goto Tools/Options/Java, click Classpath and select /usr/share/java/mysql-connector-java.jar in the file browser.

https://fedoraproject.org/wiki/QA:Testcase_MySQL_or_MariaDB_in_libreoffice-base

2

After following the above instructions and successfully connecting to the desired MySQL database, I discovered that tables containing 0000-00-00 00:00:00 in a DateTime field generated the error 'Value 0000-00-00 00:00:00' can not be loaded as java.sql.Timestamp. Finding references to "zeroDateTimeBehavior=convertToNull" as the solution was easy; the tricky part was where to enter this in LibreOffice. The quick answer: Enter it as part of the Database name field - so 'mydatabase' would become 'mydatabase?zeroDateTimeBehavior=convertToNull'. Running under Linux Mint / Ubuntu with a localhost server, this worked wonders. Happy data crunching!

1
  • 2
    This would be worth a Q/A on its own - but thank you for adding this information!
    – tohuwawohu
    Commented Jul 5, 2015 at 9:51
0

In my case (Windows and Linux) the problem was the combination of JRE / JDK and LibreOffice.

It was working with LibreOffice-7.0.3.1, JRE-1.0.8.281, mysql-connector-java-8.0.18.jar. When I upgraded either to LibreOffice-7.2 or JRE-1.0.8.301 the JDBC driver could not be loaded.

So I switched to LibreOffice-7.0.5.1 AND JRE-1.0.8.281 and seems fine. I didn't tried newer versions of JRE (282 to 300).

At LibreOffice they offer 7.2, 7.1 and 7.0 versions.

So it's working with Win-32bit and 64-bit with LibreOffice-7.0.5.1 (32-bit, latest 7.0 series), JRE-1.8.0.281 (32-bit NOT latest) and mysql-connector-java-8.0.26.jar (latest). I suppose the problem is with the mysql-connector-java-8.0-26.jar. Maybe it needs recompile with latest JDK? I tried but I don't have the time to install the dependencies.

With Linux 64 bit it's working with: LO-6.2.8.2, JDK-1.0.8.261, mysql-java-connector-8.0.18.jar (lazy to upgrade all of them). Tried with JDK-1.0.8.301 = KABOOM!

Not the answer you're looking for? Browse other questions tagged or ask your own question.