我有一个正常的PreparedStatement
插入FileItem fileItem
到BLOB列:
ps.setBinaryStream(1, fileItem.getInputStream(), (int) fileItem.getSize());
我可以输入FileItem
到NamedParameterJdbcTemplate
的问题:
我尝试使用Types.BLOB
:
MapSqlParameterSource paramSource = new MapSqlParameterSource();
paramSource.addValue("blob", fileItem.getInputStream(), Types.BLOB);
jdbcTemplate.update(INSERT_FILE, paramSource);
但是有例外
SQL state [99999]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type
Caused by: java.sql.SQLException: Invalid column type
at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:10503)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:9974)
at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:10581)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:249)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setObject(HikariProxyPreparedStatement.java)
at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:469)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:241)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:156)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:292)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:244)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633)
与jdbcTemplate
相同的错误与参数BLOB file
:
jdbcTemplate.update(INSERT_FILE, file);
使用File
和InputStream
等不同参数失败
我正在尝试保存(二进制)图像文件
它仅在我将参数类型更改为byte[]
时才起作用:
byte[] blob
并在插入中使用它:
jdbcTemplate.update(INSERT_FILE, blob);