2010-04-27 29 views
0

如果我嘗試更新FILESTREAM字段我獲得以下錯誤:updateBinaryStream上的ResultSet使用FileStream

com.microsoft.sqlserver.jdbc.SQLServerException:結果集是不可更新。

代碼:

System.out.print("Now, let's update the filestream data."); 
FileInputStream iStream = new FileInputStream("c:\\testFile.mp3"); 
rs.updateBinaryStream(2, iStream, -1); 
rs.updateRow(); 
iStream.close(); 

這是爲什麼?

表在SQL Server 2008:

CREATE TABLE [BinaryAssets].[BinaryAssetFiles](
    [BinaryAssetFileId] [int] IDENTITY(1,1) NOT NULL, 
    [FileStreamId] [uniqueidentifier] ROWGUIDCOL NOT NULL, 
    [Blob] [varbinary](max) FILESTREAM NULL, 
    [HashCode] [nvarchar](100) NOT NULL, 
    [Size] [int] NOT NULL, 
    [BinaryAssetExtensionId] [int] NOT NULL, 

查詢在Java中使用:

String strCmd = "select BinaryAssetFileId, Blob 
       from BinaryAssets.BinaryAssetFiles 
       where BinaryAssetFileId = 1"; 
stmt = con.createStatement(); 
rs = stmt.executeQuery(strCmd); 

回答

1

http://support.microsoft.com/kb/945738

This behavior is by design.

就是這樣。文章中列出了兩種解決方法:

Method 1
Change the query that returns the result set, or change the configuration of the underlying table. When you do this, SQL Server 2000 does not convert the cursor type.

Method 2
Manually create statements to update the table in SQL Server 2000.

(a bunch of code here)

0

我不知道Java的,所以我會假設你的查詢是正確的。你有沒有確保文件流功能在SQL Server中正確設置?具體而言,有在SQL Server配置管理器上的3個選項需要設置,他們是

  • 啓用的Transact-SQL 訪問FILESTREAM
  • 的I/O 流訪問啓用FILESTREAM
  • 允許遠程客戶端有 流訪問FILESTREAM數據

確保所有這些都是打勾,然後再試一次