Is there any way to connect toad for mysql without using database toolbox?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sandeep Kumar Radha Krishnan
el 19 de Oct. de 2017
Comentada: George Corliss
el 31 de Dic. de 2018
connecting the database without using database toolbox
0 comentarios
Respuesta aceptada
Walter Roberson
el 19 de Oct. de 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 comentarios
George Corliss
el 31 de Dic. de 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;
Más respuestas (0)
Ver también
Categorías
Más información sobre Database Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!