我想通過下面的代碼插入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