2015-11-10 72 views
1

我對Matlab很陌生,我試圖將單元更新到Postgresql表中。從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 

但我得到的是這樣的錯誤:

Error using database/update (line 268) Java exception occurred: java.sql.BatchUpdateException: Batch entry 0 UPDATE objects SET obj_state_new = '2' WHERE obj_name = "obj1" was aborted. Call getNextException to see the cause. at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2762) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1999) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:421) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2929)

Error in scriptingTest (line 18) update(conn,tablename,colnames,data,whereclause)

我測試的連接,它的確定。

有人能指出我正確的方向嗎?

在此先感謝

回答

2

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

的問題是圍繞價值的雙引號。

字符串文字需要包含在的報價。雙引號是標識符。

所以導致where子句中應該是這樣的:

where obj_name = 'obj1' 

where obj_name = "obj1"

+0

這並獲得成功。謝謝 – Irene