【问题标题】:Cachedrowset, JDBC and SQL server 2008 insert image problemCachedrowset、JDBC和SQL server 2008插入图片问题
【发布时间】:2011-05-01 05:14:31
【问题描述】:

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

            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 对象
每次正确时,都会插入列,但图像列保持为 NULL。 怎么了?

【问题讨论】:

    标签: java sql-server sql-server-2008 jdbc


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-06
      相关资源
      最近更新 更多