How do I set up a JDBC connector for MariaDB (or MySQL) in Base?

I want to try out JDBC, and use it to connect to my localhost MariaDB* server.

But I can’t seem to find LO documentation that clearly explains what I enter for Datasource URL and JDBC driver class, and also what else I need to do to get this working. Here is where I am stuck at the moment:

I’ve looked at the LO JDBC example documentation at this page. I think the Datasource URL should be set to either mysql://localhost:3306/ or mysql://localhost:3306/mysql.

Are Datasource URL and JDBC driver class two alternative ways to set up JDBC? Or do you need each?

If you need each, then what exactly is a JDBC driver class and what do I use for this?

As I searched for an answer to this I found a reference to setting up this screen, which I still don’t have a clue about so perhaps you could help explain that to:

Are Archive or Folder alternatives?

Thanks.


I’m using LO 5.2.2.2 on Linux, Debian 8.6 Jessie stable. Also I already have a MySQL native connector working. But because I can’t seem to get unixODBC to connect at the moment without crashing Base I was hoping to try the JDBC connector. (BTW, my unixODBC does work and I can test it w/ isql.)

For those unfamiliar with MariaDB, it’s a drop in free replacement for MySQL.

First uninstall Java 7 and install Development Kit 8u102, which you’ll need.

You don’t need JDK - JRE is fine but I would think about upgrading to version 8.

I have been using the MySQL JDBC connector(with MySQL) for quite some time now and have had no problems. This page (click here) contains instructions for connection of Base and MySQL and a link to the JDBC connector. The Class Path is discussed but is nothing more than pointing to (using Add Archive) the connector .jar file.

Once installed you create a new Base file selecting Connect to an existing database and select MySQL. This is where you enter the connection properties:

image description

And

image description

If all entered OK, you’re up and running.

Edit: 2/4/17

Although subtle, there seems to be some differences between MariaDB and MySQL. I attempted to perform an installation based upon the instructions presented by @EasyTrieve with the following results:

Start with almost newly installed OS of Debian 8.6 using Cinnamon v2.2.16 (almost because a few months back I installed LO v5.2.3.3). Using Synaptic Package Manager, installed MariaDB-server and all recommended affliates. During the installation part, you will be asked for a password (for root account).

Signing on was a bit of a pain - mentioned instructions were overly stated. You just need mysql -u root -p for first time sign-in. Then prompted for password from the installation step. Signed in so listed databases:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+

Not even the “test” database stated in the instructions here. Luckily the next page of instructions provided the creation of a DB & some tables here. show tables; and show databases; proved they were created.

LO , as mentioned, was installed. Moved over JRE 8u102 from Mint 18 and pointed to it in LO. Downloaded mariadb-java-client-1.5.7.jar - it would not work no matter what was done. Tried to get v1.5.3 but they wanted a sign in. Signed up but even when asking to v1.5.3 only 1.5.7 was offered.

Copied MySQL connector from Mint 18 - Connector/J 5.1.36, localhost:3306 & my “test” DB and connection worked immediately.

Then tested with JDBC directly and confirmed “Relationship” problem.

It’s been said here many times JDK is necessary nowadays, JRE ain’t enough.

Please read closely. JDK only necessary for MAC OSX 10. JRE works fine in Linux and Windows. I use JRE and LO 5.2.x without problem for HSQL (embedded & Server), MySQL, PostgreSQL, and SQLite. If you look, a lot of those answers are from me. See this post and also the link from there.

While that may be true, there are other softwares which either require or benefit from JDK, it usually won’t hurt to have it instead. Also, at least on Ubuntu, there’s no way to install just JRE the canon way. I think they came to the same conclusion: shouldn’t hurt having JDK.

Other software doesn’t necessarily have anything to do with LO. While installing JDK instead of JRE is not a problem (JRE is in JDK) the download is three times larger and occupies more resources. The point is, JDK is not usually needed for LO. I’m on Xubuntu and Mint. I install from Oracle and LO. Seen a number of problems using distro installs.

Interesting. Humm? Glad to hear that the Relationship issue is confirmed. Thank you. Also noticed Edit | Database Properties has same basic info, but looks a bit different depending on JDBC, or MYSQL|JDBC setup. Possibly missing or different connection parameters?? For what it’s worth, did you try org.mariadb.jdbc.Driver for the driver path, when used w/ classpath: /usr/share/java/mariadb-java-client-1.5.7.jar?

Yes tried everything I could imagine with the maria db connector. Nothing worked. The worst was the web site. Sign in, ask for 1.5.3 and still get 1.5.7.

@Ratslinger, My bad. Revised my answer, and my comment to you above last night, but comment revisions didn’t seem to take. → I have moved from 1.5.3.jar up to 1.5.7.jar. Also, sorry, but I had a mistake showing above. Was showing wrong driver path. Again, corrected to: use with /usr/share/java/mariadb-java-client-1.5.7.jar with org.mariadb.jdbc.Driver. Appreciate you checking my work.

MariaDB connector was my fault. I was trying to use com.mariadb.jdbc.Driver. org works fine. Also confirmed my suspicions - mariadb-java-client-1.5.7.jar can be located wherever wanted. I keep it in my home directory. Also confirmed MariaDB works with SQL Workbench/J (I use this more than any other). Good news as there is a lack of good tools (my opinion) for it in Linux.

@ratslinger yes that is right. I made this mistake too, at first

Everywhere you see com.mysql.jdbc… you need to change to org.mariadb.jdbc…

As well as changing the name when they forked, they mover from com to org top level just to rub in the point that they are not-for-profit :wink:

@trueriver Of course it is right as I stated so in my comment. Don’t see the purpose of the comment. I don’t even use MariaDB. Only did here for testing purposes to answer question. Actually moving away from MySQL also. Have been running parallel testing with both PostgreSQL & Firebird server.

  • [Update: Tried to also get this to work in OpenOffice but failed. Some notes in 1st paragraph below. May 30, 17]
  • [Update: Only one of the two possible methods of connecting with JDBC allows relationships to work. See below under step 4. - Feb 3, 2017 ]
  • [Update: Includes information for both Windows and Linux. - Jan 23, 2016]

STEP BY STEP

This is tested to work for Mariadb 10.1 running on a dual boot Linux Debian 8.6/Windows 10. (Also below are some tips for possibly using MySQL). EDIT: I tried to get this to work on OpenOffice 4.1.3, but can’t. First it wanted me to select the java class path archive in the home space rather than the root. I was able to manually type in the real address for it from the root. But then I got stopped when I tried to open the database below after I had entered the correct info in, especially “org.mariadb.jdbc.Driver”, but it comes back with the wrong driver class:

image description


1) If you don’t already have it installed, install MariaDB from here. (I have the Debian Linux MariaDB 10.1 Series installed.)

Test MariaDB:

  • In linux:
mysql -u [your username, normally 'root'] --password='[your password]'

You should get a prompt, and enter something like:

MariaDB [(none)]> show databases;

+--------------------+
| Database           |
+--------------------+
| bigbase            |
| information_schema |
| mysql              |
| performance_schema |
| phpmyadmin         |
+--------------------+

MariaDB [(none)]> quit

  • In Windows 10, I don’t know of a similar command line test, however you can use HeidiSQL.

  • Also in Linux HeidiSQL works nicely under Wine. (I think I like it better than phpMyAdmin.)

Data base settings are in /etc/mysql/my.cfg (in Linux), and in C:\ProgramData\MySQL\MySQL Server 5.6\my.ini (in Windows). You’ll want to have the server stopped while editing these, especially if moving the path to the database files by changing the datadir parameter.

You can stop, start or re-start the MariaDB server as follows:

a) In Linux:

sudo service mysql stop
sudo vi /etc/mysql/my.cfg
sudo service mysql start

b) In Windows:

Start | Find `Services` | Scroll down to `MySQL56` and right click on it for options to stop, restart, etc.

2) Download and install the MariaDB JDBC connector jar file from here. I have the MariaDB Connector/J 1.5 Series (v 1.5.7) installed. You’re looking for the “Universal” OS version (it’s Java after all and will run on any OS), not the source, but you can also get the source if you like to peek inside to investigate the file hierarchy naming which will be used below. The important thing is you need the mariadb-java-client-1.5.7.jar file (v1.5.3 ok too). (It’s a little confusing because it’s sometimes called a connector, and sometimes a client, and it’s both.)

  • On Linux Debian copy this jar file into /usr/share/java/. (I had a hard time finding where to copy it to. Another post suggested this location. Perhaps you could search your system for jar files. Or perhaps someone else can suggest how to determine where to put it.

  • On Windows copy this jar file into C:\Java\ (This is the suggested location, and because it is processor independent, it makes more sense than putting it into either of the two normal program file locations, i.e. C:\Program Files (x86)\ (which holds 32 bit programs) or C:\Program Files\ (which holds 64 bit programs).


3) Open LibreOffice (not LibreOffice Base, just LibreOffice) and go to Tools | Options | LibreOffice | Advanced | Set Classpath..., and click Add Archive (to add a specific Jar file, rather than a directory of them), then enter:

  • For Linux: /usr/share/java/mariadb-java-client.1.5.7.jar

  • For Windows: C:\Java\mariadb-java-client.1.5.7.jar


4) Setup your database for use. Go to File | New | Database. Select Connect to an existing database.

Tip: From here, there are two different ways to proceed: You can simply select a) JDBC, or b) you can firsts select MySQL and then JDBC. Method "a: allows you to view, open and edit your tables, but has a bug and does not allow table-to-table relationships to be viewed, edited, or work properly in subforms. If you choose method a you will get this error message when you select Tools,Relationships...

image description


4a) Method a: Select JDBC (Direct method. Disables relationships!):


4b) Method b: Select MySQL then JDBC (This method makes relationships work properly):

This does the same thing as in 4a above, it just asks a few different questions to get there.

Note, in the following screen the “Connect directly” option is now gone. Not sure why. (Think it might have to do with using the MariaDB Driver rather than the MySQL Driver.)

The Database name, Server, and Port number combine into what’s called the Datasource URL like this: mysql://hostname:port/database_name. (Notes: Perhaps someday this will use mariadb://.... But for now enter mysql://... even for MariaDB. Note, the URL seems to work even when you don’t have a web server setup. I’m guessing because we’re talking to localhost. You can also use 127.0.0.1 instead of localhost.

The JDBC Driver Class needs: “org.mariadb.jdbc.Driver” for the MariaDB JDBC driver, or (“com.mysql.jdbc.Driver” when using the MySQL JDBC driver). (You can open up the jar file and drill down into the file hierarchy to see that the folder com contains mariadb contains jdbc contains the Driver.java file.)

Also note that the free MariaDB database stuff is at their .org site, and commercial MariaDB stuff is at their .com web site.

Then save your new *.odb database file in an appropriate location and give it a better name. I suggest you name it JDBC-<some name> so you know that this is a JDBC connected database. You can use this file to later open this database with the JDBC connnector. (I don’t know why it says, ODF Database at the lower right of the screen, as it will be an .odb file you create.)

5) The results:

If all goes well you should get a screen like this:


6) Inspecting your databases properties. Finally, you can inspect how your database is setup as follows:

7) Edit | Database properties... gives:

image description

image description

I’m not sure what you could mean by “…I was really looking for a more comprehensive answer…” because the link I provided contained all of what you stated & more (including how to find out “…how the JDBC Driver Class of “com.mysql.jdbc.Driver” is arrived at…”). If you wanted “pictures” I would have pointed you here - Creating a DB but it doesn’t have the links for the connectors.

Before you re-write more of the existing documentation, you may want to peruse what is in existence - click here.

@EasyTrieve - sometimes good to have details but if you look at my edited answer things can change.

@EasyTrieve Just found this today while testing different DB performance on different. You may know this already but just in case I’ll pass it on. Native is the best way to connect - many times faster through my testing. While testing MariaDB the current MySQL native connection (pre-installed as SDBC driver for Apache Office 1.2.0) would not connect. Did find this one which did work -click here.

The problem is that it replaces the installed one and I can’t seem to find where to get the original again. Even reloading LO didn’t work. To me that is a problem because the one which works for MariaDB in v5.2.3.3 doesn’t work for MySQL in that LO version.

Again, you may already know of this. If not it may be worthwhile. It’s quite a bit faster.

@EasyTrieve Just a correction. Retested 1.2.0 connector and it worked without a problem on Debian with MariaDB. Seems the first time I tried this it failed because there actually was NO Native connector present. I also found my copy of the .otx so I have it if needed.