请教:为什么java向oracle中存图片,大于10k就不行
我在研究中遇到如题的问题。具体情况如下:
不考虑try和其他因素的代码。
File file = new File(filePath);
if(!file.exists()){
throw new RuntimeException(file.getAbsolutePath()+" not exists");
}
FileInputStream pic = new FileInputStream(file);
Connection conn = this.getConnection();
PreparedStatement pstmt = conn
.prepareStatement("insert into gphoto values (empty_blob(),?,?,?)");
pstmt.setString(1, "photoName");
pstmt.setString(2, file.getAbsolutePath());
pstmt.setString(3, String.valueOf(file.length()));
pstmt.executeUpdate();
pstmt = null;
pstmt = conn.prepareStatement("update gphoto set photobinary=? where photoresource=?");
pstmt.setBinaryStream(1, pic, pic.available());
pstmt.setString(2, file.getAbsolutePath());
pstmt.executeUpdate();
之前我只是直接存InputStream,但是一旦文件长度超过10k,就会出现错误,报连接超时错误,后来在网上看到别人说先存一个空的blob,然后更新,就变成了现在的代码。现在超过10K已经不会报错了,但是数据库中仍然没有相应的数据。在网上搜索了很多相关的回答,都没有解决问题,请高手指点一下。