0

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

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 的版本,但是一旦我知道了这些信息就会在这里更新。我还应该提到insertblob 工作得非常好:

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')
4

0 回答 0