Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 20:41   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何在没有matlabs数据库工具箱的情况下从matlab访问Postgresql数据库?

我已经尝试过使用pgmex 。不幸的是,它不适用于libpq5(matlab立即崩溃)。



回答:

要在没有数据库工具箱的情况下从matlab连接到postgres,请执行以下操作:

% Add jar file to classpath (ensure it is present in your current dir) javaclasspath('postgresql-9.0-801.jdbc4.jar'); % Username and password you chose when installing postgres props=java.util.Properties; props.setProperty('user', ''); props.setProperty('password', ''); % Create the database connection (port 5432 is the default postgres chooses % on installation) driver=org.postgresql.Driver; url = 'jdbc:postgresql://:\'; conn=driver.connect(url, props); % A test query sql='select * from '; % Gets all records ps=conn.prepareStatement(sql); rs=ps.executeQuery(); % Read the results into an array of result structs count=0; result=struct; while rs.next() count=count+1; result(count).var1=char(rs.getString(2)); result(count).var2=char(rs.getString(3)); ... end

更多&回答...
poster 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 05:13


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.