1

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?

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
Wyatt
  • 31
  • 7

1 Answers1

-1

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:

suntzu
  • 65
  • 3
  • 13