MATLAB Answers


how to connect to database

Asked by Arun Badigannavar on 22 Nov 2012

I want to connect to database with a variable name,,,,,,,,,,,,(test=database name),,,,,,,,,(a(variable)=test),,,,,,,conn=database('test','','')is the method to connect right,,,,,but i want to connect using variable name,,, conn=database('a','',''),,,,because everytimr my datase file will be selected by user,,,,

  1 Comment

how to perform this,,,everytime my database will be changing



1 Answer

Answer by Titus Edelhofer
on 22 Nov 2012


the question is not really clear. Do you mean the following?

a = 'test'; % input from user, e.g., by GUI or input
% use the variable a as database name:
d = database(a, ...);

This works fine as long as the user passes a "known" database name ...



one more question is ,I want to access different tables everytime in a single database

The tables are specified when you read data, e.g.

tableName = 'customers';
curs = exec(['SELECT * FROM ' tableName]);


here table is 'customers' ,,,and u r giving it to 'tableName' right?

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!