当前位置: 首页 > 知识库问答 >
问题:

SpringBoot oracle.jdbc.OracleDatabaseException:ORA-00932:不一致的数据类型:预期的日期得到了编号

楚俊逸
2023-03-14

2019-03-01 16:38:44.930警告55052---[nio-8080-exec-1]O.H.Engine.jdbc.spi.SQLExCeptionHelper:SQL错误:932,SQLState:42000

2019-03-01 16:38:44.930错误55052---[nio-8080-exec-1]O.H.Engine.jdbc.spi.SQLExCeptionHelper:ORA-00932:数据类型不一致:预期日期已获得编号

2019-03-01 16:38:44.946错误55052--[nio-8080-exec-1]O.A.C.C.C.[.[/].[dispatcherServlet]:路径为[]的上下文中servlet[dispatcherServlet]的servlet.Service()引发异常[请求处理失败;嵌套异常为org.SpringFramework.dao.InvalidDataAccessResourceUsageException:无法提取ResultSet;SQL[N/A];嵌套异常为org.Hibernate.exception.SqlGramMareXception:无法提取ResultSet],其根本原因为

Oracle.html" target="_blank">jdbc.OracleDatabaseException:ORA-00932:数据类型不一致:预期日期已获得编号

我最终想要的查询,我猜只是没有正确地使用spring CrudRepository形成:

select * from user_usage where Prs_Id=1104438622 and createddate > sysdate -1;

desc user_usage

Name          Null     Type           
------------- -------- -------------- 
USAGETYPEID   NOT NULL NUMBER(3)      
PRS_ID        NOT NULL NUMBER(18)     
CREATEDID     NOT NULL NUMBER(10)     
CREATEDDATE   NOT NULL DATE           
COMMENTS               VARCHAR2(4000) 
USERAGENTID            NUMBER(10)  

1)POJO

    @Entity
    @Table(name="USER_USAGE)
    public class Usage {

        @Column(name="Prs_Id")
        @Id
        private long prsId;

        @Column(name="createddate")
        private Date createddate;
    public interface UsageRepository extends CrudRepository<Usage, Date>{


        //select * from user_usage where Prs_Id=1104438622 and createddate > sysdate -1; --query that I want eventually 
         @Query("SELECT a FROM Usage a WHERE a.prsId=:prsId and a.createddate>=:createddate-1")
         Usage fetchUsageGreaterThanEqual(@Param("prsId") Long prsId, @Param("createddate") Date createddate);
    }
    @Autowired
    UsageRepository usageRepository; 
    static Date myDate;

    @GetMapping("/{prsId}")
     public Usage getUsageByPrsId(@PathVariable Long prsId) {
      return usageRepository.fetchUsageGreaterThanEqual(prsId, myDate);
     }

共有1个答案

郭弘方
2023-03-14

您的date类很可能是java.util.date

static Date myDate;

您必须将其转换为java.sql.date,如下所述

new java.sql.Date(createddate.getTime())

避免ORA-00932:不一致的数据类型:预期的日期得到的数字的问题

 类似资料: