我正在尝试使用jdbctemplate通过以下代码
在表中插入blobLobHandler 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但得到了相同的错误。
注意:小尺寸的图像会成功插入数据库,但问题是图像大小通常大于1 MB
请咨询!!!
答案 0 :(得分:0)
我认为最后一个参数应该是一个int数组:
LobHandler handler = new DefaultLobHandler();
int dbresponse = jdbcTemplate.update(
DBConstants.INSERT_INVOICE,
new Object[]{
invoiceBean.getVendorid(),
new SqlLobValue(invoiceBean.getInvoiceImage(), invoiceBean.getInvoiveImageLength(), handler),
invoiceBean.getInvoiceDate()},
new int[] {Types.INTEGER, Types.BLOB, Types.VARCHAR});