Connecting to MySQL using JDBC
Show older comments
Hi all,
Please could someone help me with the connection parameters when using MySQL and the JDBC driver?
- Is it necessary to add the datasource using ‘querybuilder’ / ‘confds’ before calling ‘database’?
- When calling database('databasename','username', 'password','driver','databaseurl'), what is the format of the driver argument? Help and other resources (<http://desk.stinkpot.org:8080/tricks/index.php/2006/02/how-to-get-matlab-to-talk-to-mysql/>) say it should be:
‘com.mysql.jdbc.Driver’.
Then I receive a “Driver Not Found/Loaded” error message.
I get the same error if I try the path to the jar file from MySQL: ‘C:/Program Files/Java/mysql-connector-java-5.1.18/mysql-connector-java-5.1.18-bin.jar’
-------------------------
Extra Info: I’ve added the driver filename to the java classpath file but am not sure if I used the correct delimiter. (I just started a new line).
Also, the whole syntax for my ‘database’ call is:
conn = database('trial','myuser','mypassword','C:/Program Files/Java/mysql-connector-java-5.1.18/mysql-connector-java-5.1.18-bin.jar','jdbc:mysql://PC1:3306/trial');
1 Comment
Riadi Marta Dinata
on 10 Feb 2016
try this code : url = 'jdbc:mysql://localhost:3306/'; conn = database('matlab_db', 'root', '', 'com.mysql.jdbc.Driver', url); curs = exec(conn,'SELECT * FROM barang'); curs = fetch(curs) curs.data
tableName = 'barang'; fields = {'kode_barang', 'nama_barang', 'deskripsi', 'harga','kategori', 'gambar', 'status'};
%allData = {'BRG004', 'KOMPUTER 4', 'Harga murah.....harga ok', '1250000', 'Komputer', 'kom4.jpg', 'Tersedia'};
var1=get(handles.guivar1,'String'); var2=get(handles.guivar2,'String'); var3=get(handles.guivar3,'String'); var4=get(handles.guivar4,'String'); var5=get(handles.guivar5,'String'); var6=get(handles.guivar6,'String'); var7=get(handles.guivar7,'String');
allData = {var1, var2, var3,var4,var5,var6, var7}; tic fastinsert(conn,tableName,fields,allData) toc
Accepted Answer
More Answers (1)
Greg
on 26 Mar 2012
1 vote
how would this work on a mac? where do I copy my JDBC driver to? (since there's no matlab folder?)
1 Comment
Nikhil
on 26 Mar 2012
So Malcolm is saying it doesn't matter where you put the driver, just be sure to add the full path i.e. 'C:/folder1/.../folderN/mysql-connector-java-5.1.15-bin.jar' to the dynamic path of Matlab using the 'javaaddpath' function.
Categories
Find more on Database Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!