【问题标题】:Error updating Postgresql from Matlab从 Matlab 更新 Postgresql 时出错
【发布时间】:2016-02-11 07:31:23
【问题描述】:

我是 Matlab 的新手,我正在尝试将一个单元格更新为 Postgresql 表。

这是我的代码

s=size(o,1);

for n=1:1:s

colnames={'obj_state_new'};
data = {num2str(2)};
tablename = 'objects';    
whereclause = ['WHERE obj_name = "obj', num2str(n), '"']
update(conn,tablename,colnames,data,whereclause)
end

但我得到的只是这个错误:

使用数据库/更新时出错(第 268 行) 发生 Java 异常: java.sql.BatchUpdateException:批处理条目 0 更新对象 SET obj_state_new = '2' WHERE obj_name = "obj1" 被中止。调用 getNextException 来查看 原因。 在 org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2762) 在 org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1999) 在 org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:421) 在 org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2929)

scriptingTest 中的错误(第 18 行) update(conn,tablename,colnames,data,whereclause)

我测试了连接,没问题。

有人能指出正确的方向吗?

提前致谢

【问题讨论】:

    标签: matlab postgresql


    【解决方案1】:

    UPDATE objects SET obj_state_new = '2' WHERE obj_name = "obj1"

    问题在于值周围的双引号。

    字符串文字需要用引号括起来。双引号用于标识符。

    所以结果 where 子句应该是这样的:

    where obj_name = 'obj1'
    

    不是 where obj_name = "obj1"

    【讨论】:

      猜你喜欢
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 2017-05-29
      • 2018-03-27
      • 1970-01-01
      相关资源
      最近更新 更多