getJdbcTemplate().queryForObject with Spring JDBC

Go To StackoverFlow.com

1

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?

2012-04-04 00:20
by Akhil K Nambiar


4

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.

2012-04-04 01:15
by Jim Garrison


6

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.

2012-04-04 01:18
by ach