% 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()
- 执行结果