将数据库导入 MATLAB 错误 [英] Importing a Database to MATLAB error

查看:28
本文介绍了将数据库导入 MATLAB 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将表导入到我的 MATLAB 工作区,但它不断向我抛出错误,未定义函数或方法 'fetch' 用于类型为 'struct' 的输入参数."

I am trying to import tables to my MATLAB workspace and it keeps throwing me an error, "Undefined function or method 'fetch' for input arguments of type 'struct'."

这是我正在尝试执行的代码:

This is my code that i am trying to execute:

dyn_conformer = exec(conn, 'SELECT * FROM dyn_conformer'); 
rs =fetch(dyn_conformer);

当我在工作区中打开对象时,它指出它是无效或关闭的连接".但是,以前我设法导入其他表,它似乎执行得很好(它们存储为游标对象).突然之间,它对我尝试导入的其他表抛出错误.

When i opened the object in the workspace, it stated that it was "Invalid or closed connection". However, previously i manage to import other tables and it seemed to execute perfectly (they are stored as a cursor object). All of a sudden, its throwing an error for other tables that i am trying to import.

我已连接到数据库,conn = database('postgres','username','password','org.postgresql.Driver','jdbc:postgresql://localhost:5433/postgres');.

推荐答案

我建议您在运行 exec 之前检查是否存在连接变量,并且它是正确建立的连接.你可以这样做:

I would recommend you to check for existing of connection variable and that it is the properly established connection before running exec. You can do it like this:

if ~exist('conn','var') || ~isconnection(conn)
    conn = database('postgres','username','password','org.postgresql.Driver',...
           'jdbc:postgresql://localhost:5433/postgres');
else
    dyn_conformer = exec(conn, 'SELECT * FROM dyn_conformer'); 
    rs =fetch(dyn_conformer);
end

这篇关于将数据库导入 MATLAB 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆