JdbcTemplate and Oracle 10

When trying to do an insert, I have: jdbcTemplate.update ("insert into ....", new Object [] {foo.getId (), foo.getName ()}) foo.getId () returns long and getName () a String. I have "NUMBER" as id type in Oracle and varchar2 for name field.

I am getting an unknown SQLtype issue. the update method has a version where I don't need to inject SQL types, but I do, and if so how?

0


source to share


1 answer


I assume you mean the Spring Framework JdbcTemplate . The methods JdbcTemplate

will try to guess the java.sql.Type for the value references, but apparently they are not guessing correctly in this case.

There are several ways to include a type:



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 a SqlParameterValue consisting of java.sql.Type and value.

Alternatively you can use JdbcTemplate.update(String, Object[], int[])

by passing in java.sql.Type array

0


source







All Articles