问题
Trying to do an insert, I have: jdbcTemplate.update("insert into....", new Object[]{foo.getId(), foo.getName()}) foo.getId() returns a long, and getName() a String. I have "NUMBER" as the id type in Oracle, and varchar2 for the name field.
I'm getting SQLtype unknown problem. the update method has a version where I do not have to put in the SQL types, but do I have to, and if so, how?
回答1:
I'm assuming you mean the Spring Framework JdbcTemplate class. The JdbcTemplate
methods will attempt to guess the java.sql.Type for value references, but apparently isn't guessing correctly in this case.
There are a couple of ways to include the type:
The JdbcTemplate.update(String, Object[])
[javadoc](http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/jdbc/core/JdbcTemplate.html#update(java.lang.String, java.lang.Object[])) indicates that you can pass SqlParameterValue instances, consisting of the java.sql.Type and a value.
Alternatively, you can use JdbcTemplate.update(String, Object[], int[])
passing an array of java.sql.Type
来源:https://stackoverflow.com/questions/300236/jdbctemplate-and-oracle-10