方法1:
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object
LobHandler lobHandler = new DefaultLobHandler(); // reusable object
jdbcTemplate.update(
"INSERT INTO imagedb (image_name, content, description) VALUES (?, ?, ?)",
new Object[] {
name,
new SqlLobValue(contentStream, contentLength, lobHandler),
new SqlLobValue(description, lobHandler)
},
new int[] {Types.VARCHAR, Types.BLOB, Types.CLOB});方法2:
NamedParameterJdbcTemplate template; //= new NamedParameterJdbcTemplate(pDs);
String INSERT_STMT = "INSERT INTO MYTABLE (ID, LONG_TEXT) VALUES (:id, :clob)";
MapSqlParameterSource paramSource = new MapSqlParameterSource();
paramSource.addValue("id", 1L, Types.NUMERIC);
paramSource.addValue("clob", "a long long text", Types.CLOB);
template.update(INSERT_STMT, paramSource);
本文介绍了如何利用JdbcTemplate和DefaultLobHandler进行高效的图像数据库插入,包括使用方法1和方法2实现图像的Varchar、Blob和CLOB类型的数据插入。
4188

被折叠的 条评论
为什么被折叠?



