about using Spring's jdbctemplate to simplify JDBC development: After Spring 3.2.2, the queryForInt in JdbcTemplate has been canceled.
Use of the Queryforxxx () method:
queryForObject instead of the queryForInt method.
queryForObject method, view source code, queryForObject (String sql, object[] args, class<t> requiredtype) {}
Example: the queryForInt () method before spring 3.2.2
JdbcTemplate jdbctemplate = new JdbcTemplate ();
String sql = "SELECT COUNT (*) from user";
Call the queryForInt () method to get the returned int type directly.
int count = jdbctemplate.queryforint (SQL);
Example: queryForObject () method
JdbcTemplate jdbctemplate = new JdbcTemplate ();
String sql = "SELECT COUNT (*) from user";
queryForObject () method, if you need to return an int type, write Integer.class, and you need to return a long type to write Long.class.
int count = Jdbctemplate.queryforobject (Sql,interger.class);
Note:When it is necessary to return what type, then the third parameter specifies what type, for example: need to return int type, write integer.class, need to return a long type to write Long.class.
This differs from the queryForInt () method in version JdbcTemplate prior to spring 3.2.2, but the essence is the same, and the difference is that we need to specify the type of parameter returned.
Summary:queryForObject () replaces the queryForInt () method with a type that requires the developer to specify an additional return.