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. 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 = ?" as well as the WHERE condition "WHERE actor_id = ?" as well? Is this possible with JdbcTemplate?
I think a simple Google search can solve your problem(s). If you just look up JdbcTemplate batchUpdate, it should guide you in the right direction. With that said, have a look at these:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.