postgresql 到本地Postgres Db的Matlab连接字符串

gcuhipw9  于 2023-05-17  发布在  PostgreSQL
关注(0)|答案(1)|浏览(96)

我已经在我的计算机上创建了一个本地Postgres Db,从那里我也运行Matlab R2021b。我试图设置连接字符串以连接到我的数据库,但没有成功。下面是我尝试的方法(dbName =“myDbName”,user =“myUser”,passw =“myPassw”)

Settings:
datasource = "PostgreSQLDataSource";
dbname = "myDbName"; % = datasource
username = "postgres";
password = "admin";
server = "127.0.0.1"; % localhost; %'server' = 'hostname'
port = 5432;
vendor = "PostgreSQL";
drivertype = "native";
%drivertype = "jdbc";
driver = "C:\Program Files (x86)\PostgreSQL\pgJDBC\postgresql-42.5.1.jar"; % = "org.postgresql.Driver";
url = ['jdbc:postgresql://' server ':' num2str(port) '/' dbname];
%opts = databaseConnectionOptions(drivertype, vendor);    
%status = testConnection(opts,"","")

Connection:
%conn = postgresql(dbname, username, password)
%conn = postgresql(datasource, username, password)
%conn = database(datasource, username, password)
%conn = database(dbname, username, password)
%conn = database(dbname, username, password, hostname, port)
%conn = database(dbname, username, password, driver, url)

这里有什么提示吗?谢谢你的好意…

h9vpoimq

h9vpoimq1#

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

相关问题