使用foo
和with open('mycsv2.csv', 'w') as f:
fieldnames = ['column1', 'column2', 'column3']
thewriter = csv.DictWriter(f, fieldnames=fieldnames)
thewriter.writeheader()
for i in range(1, 10):
thewriter.writerow({'column1':'one', 'column2':'two', 'column3':'three'})
,我要查询Spring boot 1.5.8.RELEASE
,然后在迭代所有结果时进行更新。
我曾经使用过经典的JDBC代码:
org.springframework.jdbc.core.JdbcTemplate
但是如何使用Spring JDBCTemplate类(查询方法)呢?
答案 0 :(得分:0)
感谢@JB Nizet:
jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
return con.prepareStatement("SELECT id, slug FROM user", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
}
}, new ResultSetExtractor<Void>() {
@Override
public Void extractData(ResultSet rs) throws SQLException, DataAccessException {
while (rs.next()) {
rs.updateString("slug", artistSlug);
}
return null;
}
});