0

此代码将 null 存储在数据库中。

  PreparedStatement ps;  
    String preparestmt = "update t_member set photo=? " + " where aplication_num = (select max(application_num) from t_member)";
    ps = con.prepareStatement(preparestmt);  
     ps.setBinaryStream(1,in,in.available());
    ps.executeUpdate();
    ps.close();
    in.close();
     con.commit();
     con.close();

photo 是 blob 字段,in 是包含图像文件的输入流。在插入图像中保存正确但是当我尝试更新时。它总是只存储空值。输入流也很好。我也检查了 54353 字节。帮我更新这些数据。

4

2 回答 2

0

InputStream.available() does NOT give you the number of bytes in the stream.

It returns the number of bytes that can be read without blocking.

From the JavaDocs

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. [...]

It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

(Emphasis me)

You need to find a different way to calculate the size of your BLOB. If the data is coming from a File use, File.length()

于 2013-06-12T12:35:10.880 回答
0

您能否尝试从 Java 中检索更新的图像并检查它是否已更新。我希望您在 SQLClient 中查看,它经常显示 BLOB 为空。

于 2013-06-12T12:22:40.547 回答