String lastName = this.jdbcTemplate.queryForObject("select last_name from t_actor where id = ?", new Object[]{1212L}, String.class);
I got the above line while searching for code to get data from sql using jdbc templates. I was wondering what new Object[]{1212L}
means?
It is the input parameter for the ?
, in this case the number 1212. Typically this would be derived from some user input or other data, and not hardcoded in the query.
Each "?" in the query represents a SQL parameter. The Object array represents the values to be used for the parameters. In this case, there is only one parameter hence the single value. The "L" specifies a literal of type long, in case you're not familiar with that syntax.