简体   繁体   English

如何包括jdbctemplate.batchUpdate(String sql,List的两个参数 <Object[]> batchArgs)?

[英]How to include two parameters for jdbctemplate.batchUpdate(String sql, List<Object[]> batchArgs)?

I am trying to perform an UPDATE on a MySQL database where I update only one single column full of values corresponding to the correct index position. 我正在尝试在MySQL数据库上执行UPDATE,在该数据库中,我仅更新一列,其中包含与正确的索引位置相对应的值。 Here is my current code: 这是我当前的代码:

JdbcTemplate temp = new JdbcTemplate(sqlDataSource);
List<Map<String, Object>> results = temp.queryForList("SELECT last_name FROM actor");
List<Object[]> params = new ArrayList<Object[]>();

for (Map<String, Object> row : results) {
    params.add(new Object[]{row.get("last_name"), row.get("actor_id")});
}

String sql = "UPDATE actor SET first_name= ? WHERE actor_id=?";

temp.batchUpdate(sql, params)

In this example, I am trying to update all first names in my table to the last names. 在此示例中,我尝试将表中的所有名字更新为姓氏。 My main question is how can I include a parameter for the "SET first_name = ?" 我的主要问题是如何为“ SET first_name =”添加参数? as well as the WHERE condition "WHERE actor_id = ?" 以及WHERE条件“ WHERE actor_id =?” as well? 也一样 Is this possible with JdbcTemplate? JdbcTemplate有可能吗?

I think a simple Google search can solve your problem(s). 我认为简单的Google搜索可以解决您的问题。 If you just look up JdbcTemplate batchUpdate, it should guide you in the right direction. 如果仅查找JdbcTemplate batchUpdate,它将指导您正确的方向。 With that said, have a look at these: 话虽如此,看看这些:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有关大量查询的jdbcTemplate.batchUpdate()问题 - Issue with jdbcTemplate.batchUpdate() for large list of queries jdbcTemplate.batchUpdate 跳过策略 - jdbcTemplate.batchUpdate Skip policy jdbctemplate.batchupdate 是多线程的还是并发的? - Is jdbctemplate.batchupdate multithreaded or concurrent? 列表小于 getBatchSize() 的 jdbcTemplate.batchUpdate() 抛出 IndexOutOfBoundsException 错误 - jdbcTemplate.batchUpdate() with smaller list than getBatchSize() throws IndexOutOfBoundsException error 批量插入使用 jdbcTemplate.batchUpdate 混淆 - Batch insert using jdbcTemplate.batchUpdate confusion 为 jdbcTemplate.batchUpdate() 方法编写单元测试 - Write unit test for jdbcTemplate.batchUpdate() method 有什么更好的方法检查JdbcTemplate.batchUpdate中的名称字段,名称表的SQL注入? - What better way to check SQL injection of names field, names tables in JdbcTemplate.batchUpdate? 为什么 Spring 的 jdbcTemplate.batchUpdate() 这么慢? - Why Spring's jdbcTemplate.batchUpdate() so slow? 使用spring“ jdbcTemplate.batchUpdate”进行动态插入查询的批处理 - batch processing with dynamic insert query using spring “jdbcTemplate.batchUpdate” JdbcTemplate.batchUpdate() 在一项插入错误时返回 0,但将剩余项插入 sql 服务器数据库,尽管使用 @Transactional - JdbcTemplate.batchUpdate() returns 0, on insert error for one item but inserts the remaining item into sql server db despite using @Transactional
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM