我正在尝试通过jdbc类型4(Microsoft jdbc 3.0)将图像文件(.png,200KB)插入Sql服务器(列类型varbinary(max))到Sql服务器中,这是我的代码:

            crsi.moveToInsertRow();
            crsi.updateInt(1, Integer.parseInt(txt_TargetID.getText()));
            crsi.updateBinaryStream(2, fis,f.length());
            crsi.updateString(3, txt_Name.getText());
            crsi.updateString(4, btng_Gender.getSelection().getActionCommand());
            crsi.updateString(5, dpk_Birthdate.getSelectedDateAsText());
            crsi.updateString(6, txt_IdenNo.getText());
            crsi.updateString(7, dpk_RecordDate.getSelectedDateAsText());
            crsi.insertRow();
            crsi.moveToCurrentRow();
            crsi.acceptChanges();


crsi是cachedrowsetimpl对象,fis是Fileinputstream对象
一切正常,除image列保留为NULL外,将插入这些列。
怎么了?

最佳答案

好的,我已经解决了这个问题。我应该在SQL Server中启用FILESTREAM,还必须具有Filestream组数据库,其中必须具有rowguiid和uniqueindentifier列。

此外,我不能使用cachedrowset上载文件流,但是我必须使用preparestatement上载文件流。(cachedrowset将导致同步冲突)

07-24 12:40