我想通过下面的代码插入BLOB与Spring的JdbcTemplate
LobHandler handler = new DefaultLobHandler();
int dbresponse = jdbcTemplate.update(DBConstants.INSERT_INVOICE, new Object[]{invoiceBean.getVendorid(),
new SqlLobValue(invoiceBean.getInvoiceImage(), invoiceBean.getInvoiveImageLength(), handler), invoiceBean.getInvoiceDate()},
Types.INTEGER,Types.BLOB, Types.VARCHAR);
但得到以下错误
Caused by: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
.......
Caused by: java.io.NotSerializableException: org.springframework.jdbc.core.support.SqlLobValue
我做了invoiceBean类为Serializable,但得到同样的错误插入使用的JdbcTemplate在发表blob 。
注:小尺寸的图像被成功地插入到数据库中,但问题带有大图像大小通常大于1 MB
敬请咨询!
在你的控制器,你应该确定在使用多对象的getSize方法对应的文件的字节大小。那就是你在getInvoiveImageLength方法 – artemisian
中应该返回的值是否让它工作? – artemisian
由于时间紧迫,我暂时切换为将图像上传到FileSystem。我会研究你的建议并让你知道。 – Ankit