首页 > 解决方案 > 来自 BaseX 的 xquery 错误:[sql:init] 找不到驱动程序:com.mysql.jdbc.Driver

问题描述

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> 

我已经尝试通过在 Ubuntu 上查看来安装一些JDBC结果apt,但看起来我可能需要将它们连接起来BaseX以便它们被拾取。

而且,顺便说一句,我可能需要发送用户和密码来运行上述查询,具体MySQL

标签: mysqlsqljdbcxquerybasex

解决方案


您需要安装适当的 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 客户端配置文件中的信息。


推荐阅读