4

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

leppie
  • 115,091
  • 17
  • 196
  • 297
user2737980
  • 233
  • 5
  • 13
  • This question is not a good fit for SO as we don't give examples. It is more appropriate on our mailing list and has been asked just a couple of days ago, see https://mailman.uni-konstanz.de/pipermail/basex-talk/2014-November/007690.html for some more information (so, to make it short: put it into lib/). – dirkk Nov 28 '14 at 10:59
  • thanks for comment, why there is error like " Could not initialize supplied driver: 'com.mysql.jdbc.Driver"? I already put my jdbc driver in lib directory – user2737980 Nov 28 '14 at 11:14
  • Did you restart BaseX? jars are only loaded during startup – dirkk Nov 28 '14 at 11:22
  • I am using GUI. so I closed it and reopened it. – user2737980 Nov 28 '14 at 11:28
  • I think it,s working now. – user2737980 Nov 28 '14 at 11:29

1 Answers1

4

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

Prakash Thapa
  • 1,285
  • 14
  • 27
  • Thanks for your answer. In Ubuntu, as of version 7.9 of BaseX you need to modify the shell script that runs BaseX (sudo vi /usr/bin/basex) to load the JDBC driver adding the line find_jars /usr/share/java/mysql-connector-java-5.1.16.jar 2>/dev/null , becuase in Linux there is no "lib" folder for Basex (https://www.mail-archive.com/basex-talk@mailman.uni-konstanz.de/msg04708.html). Please modify your answer adding that detail. It worked for me only on that way. – richardtk_1 Mar 02 '15 at 19:40