0

Which specific JDBC driver am I missing below?

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> 

I've tried installing a few JDBC results from looking through apt on Ubuntu, but it looks like I probably need to connect those up with BaseX so that they're picked up.

And, incidentally, I would presumably need to send a user and password to run the above query, specific to MySQL?

  • 2
    You need the MySQL driver on the classpath for BaseX. The simplest way is to follow the directions in the BaseX SQL module documentation. Download the platform independent driver package from the link they supply, extract the files and place the jar file in the BaseX lib sub-directory. For user/password see the sql:connect documentation. – chrisis Sep 22 '20 at 16:57
  • thanks @chrisis I'll pop that in the `lib` directory -- just looking for where it is on Ubuntu. – Nicholas Saunders Sep 22 '20 at 17:27
  • Not sure how the Ubuntu distribution works. I've always used the full distribution from the BaseX download page as it has everything and is the latest version. Best guess is to create a lib dir in the basex dir under your home directory and put the driver jar in there. Only a guess based on the full distribution putting jars in that location on your classpath. – chrisis Sep 23 '20 at 07:57

1 Answers1

1

You need to install the appropriate JAR, and add it to your classpath.

Using packaged drivers:

sudo apt install libmariadb-java

Edit your mysql.xq file to load org.mariadb.jdbc.Driver instead of com.mysql.jdbc.Driver, and run basex with the following command:

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

Authentication information can be provided in various ways, e.g. using parameters in the connection string, and/or information in the MariaDB/MySQL client configuration file.

Stephen Kitt
  • 2,786
  • 22
  • 32
  • I'm sure that will work, thanks. Not to be ungrateful, but that doesn't explain "where" it is that "the" lib folder "for" `BaseX` is. – Nicholas Saunders Nov 23 '20 at 09:47
  • 1
    No, it doesn’t, but your question (here) isn’t asking about that, AFAICT. I addressed the “lib” part of your questions in the Unix.SE Q&A. – Stephen Kitt Nov 23 '20 at 09:48