Best way to execute multiple jdbcTemplate queries?

Viewed 45

I have an api that is pre-fetching some data to be used in a ui dropdown screen. This would require queries to separate tables like this:

select distinct colors from table1;
select distinct categories from table2;
select distinct weights from table3;
etc

in the dao layer, I am used a namedParameterJdbcTemplate to call each query sequentially and then store them in a DTO.

try{
  colorsList = namedParameterJdbcTemplate.queryForList(getColorsQuery, 
  mapSqlParameterSource, String.class);
  categoriesList = namedParameterJdbcTemplate.queryForList(getCategoriesQuery, 
  mapSqlParameterSource, String.class);
  weightsList = namedParameterJdbcTemplate.queryForList(getWeightsQuery, 
  mapSqlParameterSource, String.class);
  filters.setCategories(categoriesList);
...
return filters;

is there a faster and more efficient way to make these db calls? Should I make the calls asynchronously? What's the best way to make multiple calls in a single api using spring boot?

0 Answers
Related