How Spring Jdbctemplate Recognizes Data Types?
Solution 1:
There is no difference between the two calls to JdbcTemplate.update, In Fact both of your calls go to the same method. There is only one update method in JdbcTemplate
Which has the following signature
publicintupdate(String sql, Object... args)throws DataAccessException
As you can see the last argument is a Java Variable Argument (...) not an Array. So you can either give individual values or an Object array to the same Variable Argument.
For your question of How JdbcTemplate knows to cast the data to match with the destination data type, It just creates a PreparedStatement and calls PreparedStatement.set*** methods based with the Order of Submitted Variable Arguments and value and actually only checks whether the given values are of String, Date or Calendar and calls PreparedStatement.setString or PreparedStatement.setTimestamp. For everything else just PreparedStatement.setObject
Post a Comment for "How Spring Jdbctemplate Recognizes Data Types?"