hi there..i really new in matlab.i want to save data in database, where i use mysql as my database.
however, how to connect the query that we have made with the button in gui..for example, button insert.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 4월 15일

0 개 추천

Matt Fig has a good set of example GUI in the MATLAB File Exchange.
Basically, if you want the user to be able to insert arbitrary text, you create an edit uicontrol, and when you want to insert it into the mysql database, you get() the 'String' property of the uicontrol. If you want the user to be able to insert arbitrary numbers, you do much the same, except after you get the String property you validate that it has numbers like you need and then you use a routine such as str2double() to convert the string into numeric values.

댓글 수: 5

Siti Maisarah
Siti Maisarah 2011년 4월 16일
ok this is my coding
function pushbutton1_Callback(hObject, eventdata, handles)
A=get(handles.edit1,'String')
B=get(handles.edit2,'String')
C = {A,B};
s.DataReturnFormat = 'cellarray';
s.ErrorHandling = 'store';
s.NullNumberRead = 'NaN';
s.NullNumberWrite = 'NaN';
s.NullStringRead = 'null';
s.NullStringWrite = 'null';
s.JDBCDataSourceFile = 'C:\Users\mai\Documents\MATLAB\test\test.mat';
s.UseRegistryForSources = 'yes';
s.TempDirForRegistryOutput = 'C:\Users\mai\AppData\Local\Temp';
setdbprefs(s)
% Make connection to database. Note that the password has been omitted.
% Using JDBC driver.
conn = database('test','root','admin','com.mysql.jdbc.Driver','jdbc:mysql://localhost/test');
% Write data to database.
insert(conn,'test',{'aa','bb'},C)
% Close database connection.
close(conn)
i use this coding but the data only save in .mat file, not in sql
Walter Roberson
Walter Roberson 2011년 4월 16일
At a guess, you are missing the SQL "commit".
Consider using fastinsert with AutoCommit:
http://www.mathworks.com/help/toolbox/database/ug/fastinsert.html
Siti Maisarah
Siti Maisarah 2011년 4월 16일
i got this error
No constructor 'com.mathworks.toolbox.database.sqlExec' with matching
signature found
i think, it cannot read data that we insert from gui..
i don't know how to call it in insert statement
insert(conn,'test',{'aa','bb'},C)
Siti Maisarah
Siti Maisarah 2011년 4월 16일
if i use this coding
insert(conn,'test',{'aa','bb'},{'hi','hi'})
then hi is successfully insert to mysql..
but when i try to call from the gui which is i use this coding,
insert(conn,'test',{'aa','bb'},{edit1.edit2})
edit1 and edit2 is my textbox in gui, the data not insert in mysql
Siti Maisarah
Siti Maisarah 2011년 4월 16일
succesfull ! thx

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

추가 답변 (0개)

카테고리

태그

질문:

2011년 4월 15일

편집:

2014년 10월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by