Java LibreOffice:无法加载“com.mysql.jdbc.driver”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27102600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:49:01  来源:igfitidea点击:

LibreOffice: 'com.mysql.jdbc.driver' cannot be loaded

javamysqljdbclibreoffice-base

提问by M Zeinstra

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

我试图在 phpMyAdmin 中通过 JDBC 连接将 LibreOffice Base 与 MySQL 数据库连接起来。

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

第一步是选择要选择的数据库: 第1步

The second step is to select which connection: Step 2

第二步是选择哪个连接: 第2步

The third step is to select your database: Step 3

第三步是选择你的数据库: 第 3 步

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

当我按“Klasse testen”(测试类)时,出现以下错误:“无法加载 com.mysql.jdbc.driver”。

Does anyone know how to avoid this error?

有谁知道如何避免这个错误?

采纳答案by tohuwawohu

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

您需要先下载并“注册”JDBC 连接器。这样做:

  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

  1. 转到http://dev.mysql.com/downloads/connector/j/并下载带有 JDBC 连接器(“平台无关”)的 ZIP 存档;您也可以下载 MSI 安装程序;在这种情况下,jar文件可以在Program Files (x86)/MySQL/MySQL Connector J/(假设是Win 7 64位系统)中找到

  2. 在本地 PC 上解压缩存档(记住其内容的路径),或者安装 MSI 文件;

  3. 在提取的文件夹结构中,有一个文件“mysql-connector-java-5.0.8-bin.jar”(名称取决于您下载的确切版本)

  4. 运行 LibreOffice(不是 Base,只是 LO);

  5. 打开菜单Tools-> Options-> LibreOffice-> Advanced-> Class Path;

    在此处输入图片说明

  6. 点击Add Archive;

    在此处输入图片说明

  7. 从步骤 1-3 中选择 jar 文件并点击OK。现在,Class Path对话框应如下所示:

    在此处输入图片说明

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

就是这样。现在,LO 知道在何处查找 MySQL JDBC 驱动程序。

回答by ADOHarra

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 namefield - so 'mydatabase' would become 'mydatabase?zeroDateTimeBehavior=convertToNull'. Running under Linux Mint / Ubuntu with a localhostserver, this worked wonders. Happy data crunching!

按照上述说明操作并成功连接到所需的 MySQL 数据库后,我发现 DateTime 字段中包含 0000-00-00 00:00:00 的表会生成错误'Value 0000-00-00 00:00:00' 可以不会作为 java.sql.Timestamp 加载。找到对“zeroDateTimeBehavior=convertToNull”的引用作为解决方案很容易;棘手的部分是在 LibreOffice 中输入它的位置。快速回答:将其作为数据库名称字段的一部分输入- 因此“mydatabase”将变为“mydatabase?zeroDateTimeBehavior=convertToNull”。在带有本地主机服务器的Linux Mint / Ubuntu 下运行,这产生了奇迹。快乐的数据处理!

回答by Ray Foss

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

如果您使用 Red Hat 像 Fedora 等 linux 发行版,您可以使用 yum 或 dnf 从存储库安装它,然后:

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

在 Base 中转到 Tools/Options/Java,单击 Classpath 并在文件浏览器中选择 /usr/share/java/mysql-connector-java.jar。

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

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

回答by Elliptical view

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

顺便说一句,对于Mariadb,其他一切都是一样的,但 jdbc 驱动程序类更改为:

org.mariadb.jdbc.Driver