简体   繁体   English

LibreOffice:无法加载'com.mysql.jdbc.driver'

[英]LibreOffice: 'com.mysql.jdbc.driver' cannot be loaded

I am trying to connect LibreOffice Base with an MySQL database, in phpMyAdmin, with a JDBC-connection. 我正在尝试使用JDBC连接将LibreOffice Base与MySQL数据库(在phpMyAdmin中)连接起来。

The first step is to select which database you want to select: 第一步是选择要选择的数据库: 步骤1

The second step is to select which connection: 第二步是选择哪个连接: 第2步

The third step is to select your database: 第三步是选择你的数据库: 第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? 有谁知道如何避免这个错误?

You need to download and "register" the JDBC connector first. 您需要先下载并“注册”JDBC连接器。 To do so: 为此:

  1. Go to http://dev.mysql.com/downloads/connector/j/ and download the ZIP archive with the JDBC connector ("Platform-Independent"); 转到http://dev.mysql.com/downloads/connector/j/并使用JDBC连接器下载ZIP存档(“平台无关”); you may alternatively download the MSI installer; 您也可以下载MSI安装程序; in this case, the jar file can be found in Program Files (x86)/MySQL/MySQL Connector J/ (assuming a Win 7 64bit system) 在这种情况下,jar文件可以在Program Files (x86)/MySQL/MySQL Connector J/ (假设是Win 7 64bit系统)

  2. Unzip the archive on your local PC (remember the path to its contents), or alternatively install the MSI file; 解压缩本地PC上的存档(记住其内容的路径),或者安装MSI文件;

  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) 在解压缩的文件夹结构中,有一个文件“mysql-connector-java-5.0.8-bin.jar”(名称取决于您下载的确切版本)

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

  5. Open Menu Tools -> Options -> LibreOffice -> Advanced -> Class Path ; 打开菜单Tools - > Options - > LibreOffice - > Advanced - > 类路径 ;

    在此输入图像描述

  6. Click Add Archive ; 单击添加存档 ;

    在此输入图像描述

  7. Select the jar file from step 1-3 and hit OK . 从步骤1-3中选择jar文件,然后单击“ 确定” Now, the Class Path dialog should look as follows: 现在,“ Class Path对话框应如下所示:

    在此输入图像描述

That's it. 而已。 Now, LO knows where to look for the MySQL JDBC Driver. 现在,LO知道在哪里寻找MySQL JDBC驱动程序。

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

org.mariadb.jdbc.Driver

If you're using Red Hat like linux distros like Fedora, you can install it from the repositories with yum or dnf and then: 如果您使用像Fedora这样的Linux发行版之类的Red Hat,可以使用yum或dnf从存储库安装它,然后:

In Base goto Tools/Options/Java, click Classpath and select /usr/share/java/mysql-connector-java.jar in the file browser. 在Base goto 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

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 . 按照上面的说明并成功连接到所需的MySQL数据库后,我发现在DateTime字段中包含0000-00-0000 00:00:00的表生成错误'Value 0000-00-00 00:00:00'可以不能作为java.sql.Timestamp加载 Finding references to "zeroDateTimeBehavior=convertToNull" as the solution was easy; 找到对“zeroDateTimeBehavior = convertToNull”的引用,因为解决方案很简单; the tricky part was where to enter this in LibreOffice . 棘手的部分是在LibreOffice中输入此内容 The quick answer: Enter it as part of the Database name field - so 'mydatabase' would become 'mydatabase?zeroDateTimeBehavior=convertToNull'. 快速回答:将其作为数据库名称字段的一部分输入 - 因此'mydatabase'将变为'mydatabase?zeroDateTimeBehavior = convertToNull'。 Running under Linux Mint / Ubuntu with a localhost server, this worked wonders. 在Linux Mint / Ubuntu下使用本地主机服务器运行,这创造了奇迹。 Happy data crunching! 快乐的数据运算!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM