【发布时间】:2019-06-25 02:58:56
【问题描述】:
使用Spring boot 1.5.8.RELEASE,使用org.springframework.jdbc.core.JdbcTemplate,我想查询SELECT id, name FROM user,然后在迭代所有结果时更新。
使用经典的 JDBC 代码,我曾经使用过:
PreparedStatement stmt = conn.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery();
...
rs.updateString("name", "toto");
...
但是如何使用 Spring JDBCTemplate 类(查询方法)呢?
【问题讨论】:
-
docs.spring.io/spring-framework/docs/current/javadoc-api/org/…:你传递了一个创建上述语句的 PreparedStatementCReator 和一个 RowCallbackHandler,它使用 ResultSet 执行你想要的操作。
-
谢谢,我在工厂试过了:
new PreparedStatementCreatorFactory(sql).newPreparedStatementCreator(new Object[]{ResultSet.CONCUR_UPDATABLE})但好像不是这样的:/ -
只需使用 lambda:
PreparedStatementCreator psc = conn -> { // create your prepared statement here }
标签: java spring jdbctemplate