How to connect mysql with Basex?

795 Views Asked by At

I have a application with Mysql as Database which is using a lot XML/HTML. I would like to process mysql data in BaseX and update database through it. Is there any simple way to connect Database? I checked http://docs.basex.org/wiki/SQL but it is not working. Can you please give me simple example what I have to do to connect? I got error An SQL exception occurred: 'No suitable driver found for jdbc:mysql://localhost:3306/test' here is my code:

let $conn := sql:connect("jdbc:mysql://localhost:3306/test")
return sql:execute($conn, "SELECT * FROM coffees WHERE price < 10")

Where should I put mysql jdbc connector (mysql-connector-java-5.1.34-bin.jar) in basex to make it work? Thanks

1

There are 1 best solutions below

1
On BEST ANSWER

First download latest version of mysql jdbc driver. Here is 5.1.36, inside this, there is .jar file, extract jar file and put in BaseX installation folder's lib directory. In windows it is

C:\Program Files (x86)\BaseX\lib

Restart the server or GUI. for GUI you should close everything, better to open from bin directory's basexgui

sql:init("com.mysql.jdbc.Driver"),
let $con := sql:connect('jdbc:mysql://localhost:3306/DB_NAME', 'DB_USER', 'DB_PASSWORD')
return sql:execute($con, "select version()")

for detail queries BaseX documentation