@Value("${db.schema.name}")
private String dbSchemaName;
private final String QUERY =
"SELECT * " +
"FROM " + dbSchemaName + ".product " +
"WHERE id = :id";
I use the static String "Query" for multiple methods. The variable dbSchemaName is defined in application.properties (db.schema.name).
public List<Object> loadData(final String id){
final MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("id", id);
return jdbcTemplate.query(QUERY, parameters, new RowMapperResultSetExtractor<>(mapper)));
}
If i execute the Method loadData(...), the dbSchemaName will not be resolved.
If i change the Query from a String variable to a method, the dbSchemaName will be resolved correctly.
private final getQuery(){
"SELECT * " +
"FROM " + dbSchemaName + ".product " +
"WHERE id = :id";
}
but I want to get Access of dbSchemaName in the Query String. For me dbSchemaName is always null in the private final String QUERY. Or is there better design than making it a method?