1

If a bean has list field , how can I use NamedParameterJdbcTemplate to insert the list of values to database using BeanPropertySqlParameterSource? If it's not possible then what should I use?

user2359634
  • 1,275
  • 5
  • 14
  • 27

1 Answers1

0

There is no direct way since there is no direct way to map a list of values to one column. There are any number of things you may be wanting it to do. This is about the closest option.

How to generate a dynamic "in (...)" sql list through Spring JdbcTemplate?

String query = "select * from table where columnName in (:listOfValues)"; List nameRecordIDs = new ArrayList(); // ... // add values to collection, then // ... Map namedParameters = Collections.singletonMap("listOfValues", nameRecordIDs); namedparameterJdbcTemplate.query(query, namedParameters,new MyMapper());

Community
  • 1
  • 1
BrianC
  • 1,793
  • 1
  • 18
  • 26