Matlab connection to Postgre DB

33 ビュー (過去 30 日間)
Davide P
Davide P 2012 年 7 月 3 日
回答済み: Paul Efford 2023 年 5 月 15 日
Hi all,
Please, can you suggest me how to connect Matlab to a DB? I have a PostgreSQL DB and I need to import data quite often. Is there any toolbox that I'm missing? I have Matlab 2008
Many thanks
Davide

回答 (1 件)

Paul Efford
Paul Efford 2023 年 5 月 15 日
dbname = 'myDbName'; % = datasource
username = "postgres";
password = 'admin';
server = 'localhost'; % 127.0.0.1'; % 'server' = 'hostname'
port = '5432';
driver = 'org.postgresql.Driver';
url = ['jdbc:postgresql://' server ':' port '/' dbname];
try
conn = database(dbname, username, password, driver, url);
conn.AutoCommit = "off";
%conn.LoginTimeout = 0;
%conn.MaxDatabaseConnections = 100;
if isopen(conn)
disp('Database connection successful');
%... put your queries here
close(conn); % close the database connection
else
disp('Database connection failed');
end
catch ME
disp(['Error while processing data from file ' ': ' ME.message]);
end

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by