updateBinaryStream on ResultSet with FileStream
- by Lieven Cardoen
If I try to update a FileStream column I get following error:
com.microsoft.sqlserver.jdbc.SQLServerException: The result set is not updatable.
Code:
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();
Why is this?
Table in 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,
Query used in Java:
String strCmd = "select BinaryAssetFileId, Blob
from BinaryAssets.BinaryAssetFiles
where BinaryAssetFileId = 1";
stmt = con.createStatement();
rs = stmt.executeQuery(strCmd);