Spring PreparedStatementCallback; SQL 无效列类型 Oracle 的未分类 SQLException

Posted

技术标签:

【中文标题】Spring PreparedStatementCallback; SQL 无效列类型 Oracle 的未分类 SQLException【英文标题】:Spring PreparedStatementCallback; uncategorized SQLException for SQL Invalid Column Type Oracle 【发布时间】:2011-12-31 00:21:54 【问题描述】:

我已将 mysql 数据库迁移到 oracle。当我使用带有修改的sql查询时,如下所示,

SELECT id, frameTypeId, ownerId, locationId FROM 
    (SELECT id, vv_frame_type_id AS
    frameTypeId, vv_owner_id AS ownerId, vv_location_id AS locationId, rownum AS rn 
    FROM signage) 
WHERE rn BETWEEN ? AND ?

当我对 oracle 数据库(提供的参数)运行查询时,我得到了结果。但是当我尝试 maven 安装项目时,出现以下错误。

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    ... 53 more
Caused by: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [select id, frameTypeId, ownerId, locationId from ( select id, vv_frame_type_id as frameTypeId, vv_owner_id as ownerId, vv_location_id as locationId, rownum as rn from vivo_signage) where rn between ? and ?]; SQL state [99999]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:602)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:673)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:713)
    at 
Caused by: java.sql.SQLException: Invalid column type
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8761)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8259)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:9012)
    at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:8993)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:230)
    at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:351)
    at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:216)
    at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:144)
    at org.springframework.jdbc.core.ArgPreparedStatementSetter.doSetValue(ArgPreparedStatementSetter.java:65)
    at org.springframework.jdbc.core.ArgPreparedStatementSetter.setValues(ArgPreparedStatementSetter.java:46)
    at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:641)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:586)
    ... 66 more

【问题讨论】:

您的问题解决了吗?如果是,请发布您的答案,我正面临类似的问题 您可能需要发布使用该 JDBC 模板运行此查询的 DAO 的代码 - 我认为问题可能出在那里,而不是查询本身。 【参考方案1】:

您可以尝试将查询创建为视图,然后从中进行选择

CREATE VIEW v_frames AS
SELECT id, frameTypeId, ownerId, locationId, rn 
FROM      
    (
    SELECT 
        id, 
        vv_frame_type_id AS frameTypeId, 
        vv_owner_id AS ownerId, 
        vv_location_id AS locationId, 
        rownum AS rn      
    FROM signage)   

【讨论】:

问题是即使我从标牌中写入 select id 我也会遇到同样的错误

以上是关于Spring PreparedStatementCallback; SQL 无效列类型 Oracle 的未分类 SQLException的主要内容,如果未能解决你的问题,请参考以下文章

Spring全家桶笔记:Spring+Spring Boot+Spring Cloud+Spring MVC

学习笔记——Spring简介;Spring搭建步骤;Spring的特性;Spring中getBean三种方式;Spring中的标签

Spring--Spring入门

Spring框架--Spring事务管理和Spring事务传播行为

Spring框架--Spring事务管理和Spring事务传播行为

Spring框架--Spring JDBC