如何在没有matlabs数据库工具箱的情况下从matlab访问postgresql数据库?

编程入门 行业动态 更新时间:2024-10-28 03:32:24
本文介绍了如何在没有matlabs数据库工具箱的情况下从matlab访问postgresql数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I tried already to use pgmex. Unfortunately it doesn't work with libpq5 (matlab immediately crashes).

推荐答案

从matlab连接到postgres而不使用数据库工具箱类似于:

To connect to postgres from matlab without the database toolbox do something similar to:

% 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', '<your_postgres_username>'); props.setProperty('password', '<your_postgres_password>'); % Create the database connection (port 5432 is the default postgres chooses % on installation) driver=org.postgresql.Driver; url = 'jdbc:postgresql://<yourhost>:<yourport>\<yourdb>'; conn=driver.connect(url, props); % A test query sql='select * from <table>'; % 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

更多推荐

如何在没有matlabs数据库工具箱的情况下从matlab访问postgresql数据库?

本文发布于:2023-10-17 11:13:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500726.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   工具箱   情况下   如何在   postgresql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!