Is there any way to connect toad for mysql without using database toolbox?

조회 수: 12 (최근 30일)
connecting the database without using database toolbox

채택된 답변

Walter Roberson
Walter Roberson 2017년 10월 19일
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
George Corliss
George Corliss 2018년 12월 31일
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;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by