Effacer les filtres
Effacer les filtres

Matlab connection to Postgre DB

3 vues (au cours des 30 derniers jours)
Davide P
Davide P le 3 Juil 2012
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

Réponses (1)

Paul Efford
Paul Efford le 15 Mai 2023
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

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by