jdbcTemplate and Oracle 10

核能气质少年 提交于 2019-12-12 05:40:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!