How can I get a GUI connecting to MATLAB via a button

5 views (last 30 days)
Hi, I am new to MATLAB and the whole world of programming so please excuse me for basic ignorance. I have a MySQL database setup and have managed to connect to it via the command line on MATLAB using this code:
dbname ='TestPLS-DAscema';
username = 'root';
password = 'password';
driver = 'com.mysql.jbdc.Driver';
uburl = ['jbdc:mysql://localhost:3306/' dbname];
javaclasspath('/home/gurvinder/Downloads/mysql-connector-java-5.1.25/mysql-connector-java-5.1.25-bin.jar');
conn = database(dbname, username, password, driver, uburl);
I have created a basic GUI with a button so that when i click on it, it will connect to the database.
I thought it would be as simple as putting the above code under the function caller so that when it clicks on the button it excutes the code giving me something like this:
function pushbutton1_Callback(hObject, eventdata, handles)
dbname ='TestPLS-DAscema';
username = 'root';
password = 'password';
driver = 'com.mysql.jbdc.Driver';
uburl = ['jbdc:mysql://localhost:3306/' dbname];
javaclasspath('/home/gurvinder/Downloads/mysql-connector-java-5.1.25/mysql-connector-java-5.1.25-bin.jar');
conn = database(dbname, username, password, driver, uburl);
But this does not seem to be working, as when i type "ping(conn)" into the command line an error is returned "database.ping at 153 invalid connection" and isconnection returns with a 0.
Like i said i am a complete noob at this and was hoping someone could point me into the correct direction to allow a simple button on a GUI to connect to a database.

Accepted Answer

Lokesh Ravindranathan
Lokesh Ravindranathan on 15 Jul 2013
Maybe a good place to start would be to use dexplore (<http://www.mathworks.com/help/database/ug/dexplore.html)>. This is the GUI interface for connecting to database. If you still have problems, contact MathWorks technical support.
  2 Comments
Gurvinder
Gurvinder on 17 Jul 2013
Hello, I have read though this documentation however when ever i use the ommand "dexplore" an error returns:
"Undefined function or variable 'dexplore'"
I know i have the database tool box as i have checked and tried running the query builder once i have established a connection to my database. But the query builder appears to be empty all the time and will not allow me to choose any schemas etc
is there another way around this without having to use the above GUI as i don't seem to have it on my university machince....also i am running MATLAB 7.6.0 R2008a if that is of any consequence.
thank you in advance
Lokesh Ravindranathan
Lokesh Ravindranathan on 17 Jul 2013
Yes, dexplore is a relatively new function. Its available started R2012b. You should be able to use querybuilder instead.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!