JDBCTemplate/NamedParameterJdbcTemplate 插入失败 FileItem/Blob
JDBCTemplate/NamedParameterJdbcTemplate failed to insert FileItem/Blob
我有一个正常的 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)
与参数 BLOB file
的 jdbcTemplate
相同的错误:
jdbcTemplate.update(INSERT_FILE, file);
使用与 File
和 InputStream
不同的参数同样失败
我正在尝试保存(二进制)图像文件
仅当我将参数类型更改为 byte[]
:
时才有效
byte[] blob
并在插入中使用它:
jdbcTemplate.update(INSERT_FILE, blob);
我有一个正常的 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)
与参数 BLOB file
的 jdbcTemplate
相同的错误:
jdbcTemplate.update(INSERT_FILE, file);
使用与 File
和 InputStream
我正在尝试保存(二进制)图像文件
仅当我将参数类型更改为 byte[]
:
byte[] blob
并在插入中使用它:
jdbcTemplate.update(INSERT_FILE, blob);