使用普通的JdbcTemplate,我可以这样做
LobHandler lobHandler = new DefaultLobHandler();
InputStream inputStream= jdbcTemplate.queryForObject(
"SELECT data FROM blob_table WHERE id = ?",
new Object[]{id},
(rs, rowNum) -> lobHandler.getBlobAsBinaryStream(rs, 1)
);
jdbcTemplate.update("INSERT INTO blob_table (id, data) VALUES (?, ?)", ps -> {
ps.setString(1, id);
ps.setBinaryStream(2, inputStream);
});
但是我应该如何使用NamedParameterJdbcTemplate呢?
答案 0 :(得分:0)
这似乎可行:
MapSqlParameterSource idParameter = new MapSqlParameterSource("id", id);
LobHandler lobHandler = new DefaultLobHandler();
InputStream result = jdbcTemplate.queryForObject(
"SELECT data FROM blob_table WHERE id = :id",
idParameter,
(rs, rowNum) -> lobHandler.getBlobAsBinaryStream(rs, 1)
);
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("id", id);
parameters.addValue("data", inputStream);
jdbcTemplate.update("INSERT INTO blob_table (id, data) VALUES (:id, :data)", parameters);