PGSQL JDBC BLOB更新给出错误

时间:2013-11-13 01:26:52

标签: java jdbc bytea jdbc-postgres

我之前已经下载了一些文件并将它们存储在PGSQL数据库中。我在'content'列中使用了'bytea'类型,我将文件内容存储为二进制流。现在,如果文件已更新(在托管文件的原始源),那么我需要更新数据库中的相应条目。所以我已经将Java PreparedStatement更新如下:

PreparedStatement sqlStatement;

// args below is the list of column objects
for(int i=0; args != null && i < args.size(); i++)
{
    if(i+1 == blobIndex)
        sqlStatement.setBinaryStream(blobIndex, (InputStream) args.get(i), blobSize);
    else
        sqlStatement.setObject(i+1, args.get(i));   
}
sqlStatement.executeUpdate();

我收到以下错误:

org.postgresql.util.PSQLException: ERROR: syntax error at or near ","
  Position: 143
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:334)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$StatementHandler.invoke(AbstractJdbc23PooledConnection.java:455)
    at com.sun.proxy.$Proxy1.executeUpdate(Unknown Source)
    at PGSqlAdapter.executeQuery(PGSqlAdapter.java:99)

我正在使用JDBC / Postgresql版本(在Maven上):9.1-901-1.jdbc4

修改 这是正在执行的最终sql语句(通过调试模式获得):

UPDATE  file SET  content='<stream of 61079 bytes>', sourceUserID='d@gmail.com', accountid='4d2b4396-c5bf-3051-b257-73a8d8fea41c', source='googledrive', path='[{"id":"0Bwn0zc8sQE8CX3FxQTNvNG8tYTg","isRoot":false,"kind":"drive#parentReference","parentLink":"https://www.googleapis.com/drive/v2/files/0Bwn0zc8sQE8CX3FxQTNvNG8tYTg","selfLink":"https://www.googleapis.com/drive/v2/files/0Bwn0zc8sQE8CdEx6Y1dabHhLUE0/parents/0Bwn0zc8sQE8CX3FxQTNvNG8tYTg"}]', userid='x@x.com', extraparams='{"crc":"2fc453da4ce077f7e267627fbc780d93","isroot":false,"lastmodified":1379712225540,"parentid":"0Bwn0zc8sQE8CX3FxQTNvNG8tYTg","filetype":"image/jpeg","nodeid":"0Bwn0zc8sQE8CdEx6Y1dabHhLUE0"}', filename='SPACE.JPG', size='61079' WHERE userid='x@x.com', accountid='4d2b4396-c5bf-3051-b257-73a8d8fea41c', source='googledrive', filename='SPACE.JPG', path='[{"id":"0Bwn0zc8sQE8CX3FxQTNvNG8tYTg","isRoot":false,"kind":"drive#parentReference","parentLink":"https://www.googleapis.com/drive/v2/files/0Bwn0zc8sQE8CX3FxQTNvNG8tYTg","selfLink":"https://www.googleapis.com/drive/v2/files/0Bwn0zc8sQE8CdEx6Y1dabHhLUE0/parents/0Bwn0zc8sQE8CX3FxQTNvNG8tYTg"}]', sourceUserID='d@gmail.com'

我现在不知道PGSQL的版本,但是一旦我知道了这些信息,就会在这里更新。我还应该提到blob的insert完全可以正常工作:

INSERT INTO file (content,sourceUserID,accountid,source,path,userid,extraparams,filename,size) VALUES ('<stream of 2081345 bytes>','d@gmail.com','4d2b4396-c5bf-3051-b257-73a8d8fea41c','googledrive','[{"id":"0Bwn0zc8sQE8CX3FxQTNvNG8tYTg","isRoot":false,"kind":"drive#parentReference","parentLink":"https://www.googleapis.com/drive/v2/files/0Bwn0zc8sQE8CX3FxQTNvNG8tYTg","selfLink":"https://www.googleapis.com/drive/v2/files/0Bwn0zc8sQE8CaU80engzNDJlSkU/parents/0Bwn0zc8sQE8CX3FxQTNvNG8tYTg"}]','x@gmail.com','{"crc":"244fb7ce4677a05de7a8e92175b9cbcf","isroot":false,"lastmodified":1379712217782,"parentid":"0Bwn0zc8sQE8CX3FxQTNvNG8tYTg","filetype":"image/png","nodeid":"0Bwn0zc8sQE8CaU80engzNDJlSkU"}','MARBLE24.PNG','2081345')

0 个答案:

没有答案