Creating multiple connections to a database using loops- Database toolbox.

9 ビュー (過去 30 日間)
daniel.x16
daniel.x16 2011 年 5 月 31 日
Hi,
I am trying to create multiple connections to a database for a program I am writing to graph data from different databases next to eachother.
The basic command to connect to a database is:
conn=database(database_name,'IP Address','Password')
datbase_name is the name of the database
and IP Address and Password must be enclosed in single quotes.
What I am trying to do is basically (for a variable number n...a user can input how many databases he wants to connect to. I have all the database names in a matrix called DB_name...so I want DB_name(i) to call the i-th entry)
for i=1:n
conn(i)=database(DB_name(i),'192.168.94.94','password')
end
However, this does not work. I am not entirely sure why it doesn't. I have been looking all through the forums, and have been unable to get any of the solutions to work with my problem.
I can do it with a ton of 'for' statements, this is impractical, and I want to do it with a loop to make sure I can support any number of database name entries.
Any help would be greatly appreciated!

採用された回答

Walter Roberson
Walter Roberson 2011 年 5 月 31 日
You probably need DB_name{i} instead of DB_name(i)
Though possibly you want DB_name(i,:)

その他の回答 (1 件)

daniel.x16
daniel.x16 2011 年 5 月 31 日
This sort of works...now I have:
for i=1:n
conn{i}=database(DB_names{i},'localhost','')
end
But instead of making conn1,conn2,conn3....connn, it just makes 'conn', as a 1 by n cell. (Basically it puts each connection in ONE matrix, I want it in n matrices.) How can I make conn1, conn2,...connn?
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 5 月 31 日
Please do not do that. Please read this FAQ:
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by