Is there any way to connect toad for mysql without using database toolbox?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sandeep Kumar Radha Krishnan
il 19 Ott 2017
Commentato: George Corliss
il 31 Dic 2018
connecting the database without using database toolbox
0 Commenti
Risposta accettata
Walter Roberson
il 19 Ott 2017
Yes.
If you are using MS Windows then you can use activexserver() to connect with a database program.
If you are not using Windows then you can use loadlibrary() to call into a .so (shared library) such as libsql or libmysql
17 Commenti
George Corliss
il 31 Dic 2018
GREAT! You saved me a couple days' figuring out.
My slightly polished version of your Matlab code:
% See: Is there any way to connect to mysql without using database toolbox?
% https://www.mathworks.com/matlabcentral/answers/362076-is-there-any-way-to-connect-toad-for-mysql-without-using-database-toolbox
driver = '{MySQL ODBC 8.0 ANSI Driver}';
server = 'localhost';
dbName = 'test';
user = 'venu';
passwd = 'venu';
% Connect to MySQL server using Connector/ODBC
conn = actxserver('ADODB.Connection');
conn.ConnectionString ...
= [ 'DRIVER=' driver '; ' ...
'SERVER=' server '; ' ...
'DATABASE=' dbName '; ' ...
'UID=' user '; ' ...
'PWD=' passwd '; ' ...
'OPTION=3' ];
fprintf('ConnectionString: %s\n', conn.ConnectionString);
conn.Open;
% Create table
conn.Execute('DROP TABLE IF EXISTS my_ado');
conn.Execute('CREATE TABLE my_ado(id int not null primary key, name varchar(20), txt text, dt date, tm time, ts timestamp)');
% Direct insert
conn.Execute('INSERT INTO my_ado(id, name, txt) values(1, 100, ''venu'')');
conn.Execute('INSERT INTO my_ado(id, name, txt) values(2, 200, ''MySQL'')');
conn.Execute('INSERT INTO my_ado(id, name, txt) values(3, 300, ''Delete'')');
rs = actxserver('ADODB.Recordset');
rs.CursorLocation = 'adUseServer';
% Fetch the initial table
query = 'SELECT * FROM my_ado;';
fprintf('Query: %s\n', query);
rs.Open(query, conn);
fprintf('rs.RecordCount: %d\n', rs.RecordCount);
rs.MoveFirst;
fprintf(['\n', repmat('-', 1, 10), ' Initial my_ado Result Set ', repmat('-', 1, 10), '\n']);
for flditer = 0 : rs.Fields.Count - 1
fld = rs.Fields.Item(flditer);
fprintf('%s\t', fld.Name);
end
fprintf('\n');
while ~rs.EOF
flditer = 0;
fld = rs.Fields.Item(flditer);
fprintf('%2d\t', fld.Value);
for flditer = 1 : rs.Fields.Count - 1
fld = rs.Fields.Item(flditer);
fprintf('%s\t', fld.Value);
end
rs.MoveNext;
fprintf('\n');
end
rs.Close;
conn.Close;
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Database Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!