Spring JDBC 和 Oracle DB 12c:java.sql.SQLException:无效的列类型。为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27314566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 11:35:56  来源:igfitidea点击:

Spring JDBC & Oracle DB 12c: java.sql.SQLException: Invalid column type. Why?

javaspringspring-bootspring-jdbcoracle12c

提问by Micha? Kowalczyk

I'm struggling with following exception:

我正在努力解决以下异常:

org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [update EVALUATION_SHEET set STATUS=?, LAST_EDITED=? where id=?]; SQL state [99999]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type

Which is thrown here:

这是抛出这里:

jdbcTemplate.update("update E_SHEET set STATUS=?, LAST_EDITED=? where id=?",
                new Object[]{eSheet.getStatus().ordinal(), eSheet.getLastEditDate(), eSheet.getId()},
                new Object[]{OracleTypes.NUMBER, OracleTypes.TIMESTAMP, OracleTypes.NUMBER});

The database table is created as follows:

数据库表创建如下:

create table E_SHEET (
  ID number not null unique,
  ID_POSITION number not null,
  STATUS number default 0 not null,
  ID_EXAMINER number not null,
  LAST_EDITED timestamp not null);

I have no idea what is causing the problem. This method:

我不知道是什么导致了这个问题。这种方法:

 eSheet.getLastEditDate()

returns java.util.Date object. I am using Spring JDBC template with Spring Boot and Oracle DB 12c as a datasource.

返回 java.util.Date 对象。我将 Spring JDBC 模板与 Spring Boot 和 Oracle DB 12c 一起用作数据源。

回答by Weggyboy

after the spring documentation http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html, an update would work like this:

在 spring 文档http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html 之后,更新将像这样工作:

jdbcTemplate.update("update t_actor set last_name = ? where id = ?", "Banjo", 5276L);

jdbcTemplate.update("update t_actor set last_name = ? where id = ?", "Banjo", 5276L);

or like this

或者像这样

jdbcTemplate.update("update orders set shipping_charge = shipping_charge * ? / 100 where id = ?", pct, orderId);

jdbcTemplate.update("update orders set shipping_charge = shipping_charge * ? / 100 where id = ?", pct, orderId);

But you are passing arrays of Objects as parameters to the method.

但是您将对象数组作为参数传递给方法。

Why not just this?

为什么不只是这个?

jdbcTemplate.update("update E_SHEET set STATUS=?, LAST_EDITED=? where id=?", eSheet.getStatus().ordinal(), eSheet.getLastEditDate(), eSheet.getId());

jdbcTemplate.update("update E_SHEET set STATUS=?, LAST_EDITED=? where id=?", eSheet.getStatus().ordinal(), eSheet.getLastEditDate(), eSheet.getId());