[英]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.