【问题标题】:xquery error from BaseX: [sql:init] Could not find driver: com.mysql.jdbc.Driver来自 BaseX 的 xquery 错误:[sql:init] 找不到驱动程序:com.mysql.jdbc.Driver
【发布时间】:2021-01-08 16:18:46
【问题描述】:

下面的missing我是哪个JDBC驱动程序?

nicholas $ 
nicholas $ basex mysql.xq 
Stopped at /home/nicholas/flwor/mysql.xq, 3/9:
[sql:init] Could not find driver: com.mysql.jdbc.Driver
nicholas $ 
nicholas $ cat mysql.xq 
xquery version "3.0";

sql:init("com.mysql.jdbc.Driver"),
let $con := sql:connect("jdbc:mysql://localhost:3306/northwind")
return sql:execute($con, "SELECT first_name FROM customers LIMIT 3;")


nicholas $ 
nicholas $ mysql -h localhost -P 3306 --protocol=tcp -u user -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2901
Server version: 8.0.21 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> SELECT first_name FROM northwind.customers LIMIT 3;
+------------+
| first_name |
+------------+
| Alexander  |
| Amritansh  |
| Andre      |
+------------+
3 rows in set (0.00 sec)

mysql> 

我已经 tried 安装了一些 JDBC 的结果,这些结果是通过在 Ubuntu 上查看 apt 得到的,但看起来我可能需要 connect 那些使用 BaseX 的人,以便他们被选中。

顺便说一句,我可能需要发送用户和密码来运行上述查询,specific 到 MySQL?

【问题讨论】:

  • 您需要在 BaseX 的类路径中安装 MySQL 驱动程序。最简单的方法是按照 BaseX SQL 模块文档中的说明进行操作。从他们提供的链接下载平台无关的驱动程序包,提取文件并将 jar 文件放在 BaseX lib 子目录中。对于用户/密码,请参阅 sql:connect 文档。
  • 谢谢@chrisis,我会把它放到lib 目录中——只是在Ubuntu 上寻找它的位置。
  • 不确定 Ubuntu 发行版是如何工作的。我一直使用 BaseX 下载页面的完整发行版,因为它拥有一切并且是最新版本。最好的猜测是在你的主目录下的 basex 目录中创建一个 lib 目录,并将驱动程序 jar 放在那里。仅基于将 jars 放在类路径上的该位置的完整发行版的猜测。

标签: mysql sql jdbc xquery basex


【解决方案1】:

您需要安装适当的 JAR,并将其添加到您的类路径中。

使用打包的驱动程序:

sudo apt install libmariadb-java

编辑您的mysql.xq 文件以加载org.mariadb.jdbc.Driver 而不是com.mysql.jdbc.Driver,并使用以下命令运行basex:

JAVA_CLASSPATH=/usr/share/java/mariadb-java-client.jar basex

可以通过多种方式提供身份验证信息,例如使用连接字符串中的参数,和/或 MariaDB/MySQL 客户端配置文件中的信息。

【讨论】:

  • 我相信这会奏效,谢谢。不要忘恩负义,但这并不能解释“用于”BaseX 的“lib 文件夹”在“哪里”。
  • 不,它没有,但你的问题(这里)不是问这个,AFAICT。我在 Unix.SE 问答中解决了您问题的“lib”部分。
猜你喜欢
  • 2012-02-05
  • 1970-01-01
  • 1970-01-01
  • 2016-12-24
  • 2013-07-05
  • 2011-09-16
  • 1970-01-01
  • 2016-09-15
  • 1970-01-01
相关资源
最近更新 更多