zdsg
发布于

Oushudb对matlab的支持

  • 执行代码
% Add jar file to classpath (ensure it is present in your current dir)
javaclasspath('C:\Users\xx\Desktop\need\科技\常用测试包\postgresql-42.2.12.jar');

% Username and password you chose when installing postgres
props=java.util.Properties;
props.setProperty('user', 'xxx');
props.setProperty('password', 'xxx666');

% Create the database connection (port 5432 is the default postgres chooses
% on installation)
driver=org.postgresql.Driver;
url = 'jdbc:postgresql://192.168.80.118:5432/postgres';
conn=driver.connect(url, props);

% A test query
sql='select * from t1'; % Gets all records
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();

% Read the results into an array of result structs
count=0;

while rs.next()
    count=count+1;
end

fprintf('the count of lines is %d\n',count)

rs.close()
  • 执行结果
评论(1)
  • zdsg
    zdsg 回复

    安装好软件后,需要替换上图中 javaclasspath 包含的驱动的路径以及名称为自己本地的相关信息,并替换数据库的连接信息即可

test