Hey,
I'm trying to accommodate to Spring JDBC, but what bugs me is using these anonymous classes, where we cannot pass any local variables unless they are final which might be easy to arrange, but what about if I need to loop an array or collection ? I cannot declare "FedModel fm" to be final as it gets reinitialized in the loop, but I need to call the execute method 100 times. This is concrete scenario where I have the problem, cause I don't know any other way how to insert BLOB into a database.
for (int i = 0; i < fedModels.size(); i++) {
FedModel fm = fedModels.get(i);
jdbcTemplate.execute("INSERT INTO items (name, video_blob) VALUES (?, ?)",
new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
protected void setValues(PreparedStatement ps, LobCreator lobCreator)
throws SQLException {
ps.setString(1, fm.getName());
ps.setString(2, fm.getDifficultyLevel());
ps.setString(3, fm.getEquipment());
lobCreator.setBlobAsBinaryStream(ps, paramIndex, contentStream, contentLength);
}
});
}
The only thing I can think of, is creating a static Nested class that extends AbstractLobCreatingPreparedStatementCallback and adds constructor for fedModels so that I could do the loop inside. But it would be easier using only JDBC.