Accessing MySQL Tables via OpenOffice

OpenOffice (BASE) is a (free) generic database program. It provides a nice GUI for creating table, viewing data, and the like.

In my case, I needed a way to pump data from dbf files to MySQL. I could have used a number of other programs, but I thought that this would be a good excuse to learn another.

By the way, there are a number of not free programs that claim to do the same thing. Just use a search engine to find one.

Loading JDBC

To access an existing MySQL database, use File / New / Database to open a Wizard. According to the built-in help (press either the Help button or F1 while the Wizard is displayed), there are several options - I selected JDBC. I selected everything as instructed by the JDBC Connection help page, but when I clicked Test class, the driver failed to loaded.

The solution was to download the MySQL JDBC driver (Connect/J) and install it as instructed on the JDBC Connection help page.

When writing this page (ie, after I had a working system), I discovered another option - the MySQL Connector for I am running OpenOffice 3.1.1 - which is supported by this connector. However, the local OpenOffice help does not mention it.

Even the Connect/J specific download page, which has links to all the other MySQL Connectors, does not have a reference to this.

Opening a Port

After JDBC was installed, the next step in the Wizard was to select a database and test the connection. I tried multiple user id and password combinations and nothing worked.

Since I was using 2 systems, one with OpenOffice and separate with MySQL, I finally decided to check the firewall on the MySQL system.

When I opened port 3306, it fixed the problem.

On the MySQL system,

If I had had experience with working system, I might have found this much sooner. Basically, with the port blocked, when you click Test it takes a long time before a dialog box indicates no response. However, when it is open, failed login attempts are reported immediately.

Note that the default root user id will not work - so create another for this.

Opening a MySQL database

Using OpenOffice, I have not found a way to create a new MySQL database (directory). Assuming that you have created one in some other manner, the following describes how to connect to it. Before JDBC was loaded, the JDBC driver class field was automatically filled in. Now you have to type it yourself .. without any help. (User hostile interface.) Note that there must not be any extra spaces before or after com.mysql.jdbc.Driver - which are easy to produce with copy and paste. (Very frustrating.)

By default, the root username works only on the localhost and will not work over a network. This is a good thing - create a separate username and password for remote access.

Security fail - Reopening an *.odb file does not required either a username or a password.

Linking to dbf files

To link to an existing dbf file, create a new *.odb file and associate it with an existing directory. When you right click on an existing table, the menu provides

Converting dbf to MySQL

Using OpenOffice, it is possible to convert dbf files to MySQL using a fairly simple (not really) procedure. Think of a database as a collection of tables in a directory. When there is an issue, there will be an error dialog. You have to click the More button and then the red X to see which field is the problem. Then you use the mysql.exe console to determine which record caused the problem. Next I use OpenOffice to locate the bad record (count+1) in the source (dbf) table and inspect the data.

I don't get it - a number of fields created by this process were one character smaller than the originals. Specifically,

Decimal fields are stored in dbf files as ascii values. It is possible that the database is defined wrong (but still holds the data) or that OpenOffice has a fairly major design problem. (I am pretty sure that OpenOffice has the problem .. but you never know.)

At any rate, when pasting a table (ie, making a copy), there is an option to modify the proposed data types .. so I did. At that point, the data was transferred without any problems.


Author: Robert Clemenzi
URL: http:// / Databases / MySQL / OpenOffice.html