Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top