Error in calling Stored Proc from Spring JPA - spring

Error in Stored proc execution when called from Java
#PersistenceContext
private EntityManager em;
#Override
public String funcName(String valueId) {
StoredProcedureQuery query = em.createStoredProcedureQuery("proc_name");
query.registerStoredProcedureParameter("input_id", String.class, ParameterMode.IN);
query.setParameter("input_id", valueId);
query.execute();
return "Stored Procedure Exceuted";
}
}
The value of valueId is present in query.setParameter("input_id", valueId);
And I get the following error
2020-03-19 20:10:55.904 DEBUG 8684 --- [io-7080-exec-10] o.h.SQL :{call proc_name(?)}
2020-03-19 20:10:56.460 WARN 8684 --- [io-7080-exec-10] o.h.e.j.s.SqlExceptionHelper : SQL Error: 6550, SQLState: 65000
2020-03-19 20:10:56.460 ERROR 8684 --- [io-7080-exec-10] o.h.e.j.s.SqlExceptionHelper : ORA-06550: line 1, column 7:
PLS-00201: identifier 'proc_name' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Please help me resolve
I get the same error even if i use query.getResultList()
My stored proc updates the values in the table and expects only one parameter
create or replace procedure proc_name(input_id in varchar2)

Related

SQLExceptionHelper : Input parameter not set, Index : 0

I am using spring-data-rest & hibernate to expose a table "File(Id, Name)" from a SAP IQ(Sybase IQ) database. The below error occurs when I do a "GET" on the "File" table using "curl http://localhost:8080/files/1".
2022-07-20 20:01:03 WARN [http-nio-8081-exec-1] o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: JZ0SA
2022-07-20 20:01:03 ERROR [http-nio-8081-exec-1] o.h.e.jdbc.spi.SqlExceptionHelper - JZ0SA: Prepared Statement: Input parameter not set, index: 0.
2022-07-20 20:01:03 INFO [http-nio-8081-exec-1] o.h.e.i.DefaultLoadEventListener - HHH000327: Error performing load command
org.hibernate.exception.GenericJDBCException: could not extract ResultSet
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
I have the same table in "Sybase 16" but it is working perfectly with the same code base.
Anyone faced similar issue?
Thanks in advance

How can I use a function say digits with Spring JPA and native query and DB2

I want to be able to use this function and them pass the parameter. But I get this error, it is almost that spring jpa or java prepared statements are not allowing me to do this.
The code looks like the following in the logs.
Hibernate: UPDATE DB2PROD.GLOBAL_TABLE
SET CONTRACT_ID = DIGITS( ? )
WHERE GLOBAL_ID = ?
#Query(value = "UPDATE DB2PROD.GLOBAL_TABLE \n" +
" SET CONTRACT_ID = DIGITS( :indicator ) \n" +
" WHERE GLOBAL_ID = :id ", nativeQuery = true)
int update(final Integer indicator, final String id);
And the error:
2022-03-11 15:54:25.982 WARN 95241 --- [ scheduling-1]
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: -418, SQLState:
42610 2022-03-11 15:54:25.982 ERROR 95241 --- [ scheduling-1]
o.h.engine.jdbc.spi.SqlExceptionHelper : DB2 SQL Error:
SQLCODE=-418, SQLSTATE=42610, SQLERRMC=null, DRIVER=4.25.13 2022-03-11
15:54:25.982 WARN 95241 --- [ scheduling-1]
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: -516, SQLState:
26501 2022-03-11 15:54:25.983 ERROR 95241 --- [ scheduling-1]
o.h.engine.jdbc.spi.SqlExceptionHelper : DB2 SQL Error:
SQLCODE=-516, SQLSTATE=26501, SQLERRMC=null, DRIVER=4.25.13 2022-03-11
15:54:25.983 WARN 95241 --- [ scheduling-1]
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: -518, SQLState:
07003 2022-03-11 15:54:25.983 ERROR 95241 --- [ scheduling-1]
o.h.engine.jdbc.spi.SqlExceptionHelper : DB2 SQL Error:
SQLCODE=-518, SQLSTATE=07003, SQLERRMC=null, DRIVER=4.25.13 2022-03-11
15:54:26.017 ERROR 95241 --- [ scheduling-1]
c.p.p.m.contacts.service.ContactService : Error on save contact
Db2 can't determine a data type of the parameter in the DIGITS (?) expression.
You must define it explicitly with CAST like:
DIGITS (CAST (? AS INT))
or
DIGITS (CAST (? AS DEC (5)))
etc.

Spring JPA Oracle SUBSTRING

I'm using a custom #Query with Spring JPA like this:
#Query(value = "select ua from USER_ACCOUNT ua where SUBSTRING(ssn, -4, 4) = :ssn and last_nm = :lastName and birth_dt = :dateOfBirth")
UserAccount findByLastFourOfSSNAndLastNameAndDateOfBirth(#Param("ssn") String lastFourOfSSN, #Param("lastName") String lastName, #Param("dateOfBirth") Date dateOfBirth);
It works without any problems when I run it locally, but as soon as I deploy it out to the development environment I get:
[2017-12-19T23:02:59,048] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper SQL Error: 904, SQLState: 42000
[2017-12-19T23:02:59,048] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper ORA-00904: "SUBSTRING": invalid identifier
[2017-12-19T23:02:59,049] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[User Store] Servlet.service() for servlet [User Store] in context with path [] threw exception [org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
java.sql.SQLSyntaxErrorException: ORA-00904: "SUBSTRING": invalid identifier
The development environment is pretty much identical to my local. Same database, same version of Tomcat. Am I just missing something obvious here?
EDIT: SQL being generated:
select useraccoun0_.GUID as GUID1_5_, useraccoun0_.CREATED_BY as CREATED_BY2_5_, useraccoun0_.CREATED_DT as CREATED_DT3_5_, useraccoun0_.DB_NOTE as DB_NOTE4_5_, useraccoun0_.LAST_CHANGED_BY as LAST_CHANGED_BY5_5_, useraccoun0_.LAST_CHANGED_DT as LAST_CHANGED_DT6_5_, useraccoun0_.ACCOUNT_RECOVERY_EMAIL as ACCOUNT_RECOVERY_E7_5_, useraccoun0_.ACCOUNT_RECOVERY_PHONE as ACCOUNT_RECOVERY_P8_5_, useraccoun0_.BIRTH_DT as BIRTH_DT9_5_, useraccoun0_.DISABLED_IND as DISABLED_IND10_5_, useraccoun0_.DISABLED_DT as DISABLED_DT11_5_, useraccoun0_.DISABLED_REASON as DISABLED_REASON12_5_, useraccoun0_.email as email13_5_, useraccoun0_.FAILED_LOGIN_CNT as FAILED_LOGIN_CNT14_5_, useraccoun0_.FAILED_PASSWORD_RESET_DT as FAILED_PASSWORD_R15_5_, useraccoun0_.FIRST_NM as FIRST_NM16_5_, useraccoun0_.LAST_FAILED_LOGIN_DT as LAST_FAILED_LOGIN17_5_, useraccoun0_.LAST_LOGIN_DT as LAST_LOGIN_DT18_5_, useraccoun0_.LAST_NM as LAST_NM19_5_, useraccoun0_.LOCKED_IND as LOCKED_IND20_5_, useraccoun0_.LOCKED_CNT as LOCKED_CNT21_5_, useraccoun0_.LOCKED_DT as LOCKED_DT22_5_, useraccoun0_.USER_PASSWORD as USER_PASSWORD23_5_, useraccoun0_.PASSWORD_CHANGED_DT as PASSWORD_CHANGED_24_5_, useraccoun0_.PHONE_NBR as PHONE_NBR25_5_, useraccoun0_.REQUIRE_PASSWORD_RESET_IND as REQUIRE_PASSWORD_26_5_, useraccoun0_.SSN as SSN27_5_, useraccoun0_.USER_NM as USER_NM28_5_ from USER_ACCOUNT useraccoun0_ where substr(useraccoun0_.SSN, -4, 4)=? and last_nm=? and birth_dt=?

Why this error is showing while writing code

Compilation errors for PROCEDURE MTR.MTR_DAILY_MAIL_REPORT_PRC1
Error: PLS-00201: identifier 'EXCELFILE.EXCEL_OPEN' must be declared
Line: 54
Text: Excelfile.Excel_Open(Excel_Data);

MyBatis - Insert with TypeHandler - java.lang.ClassNotFoundException

Mapper.xml
<insert id = "insertVacation" parameterType = "Vacation">
INSERT INTO ferias (audit_dt, audit_usuario, audit_st_ope,
feri_cfun_cd_mat, feri_fepa_ano, feri_sq, feri_dt_inicio, feri_dt_fim,
feri_fsfr_cd, feri_st_pag, feri_ds_obs, feri_st_ad13sal, feri_dt_pagref,
feri_st_autorizado, fepa_st_recebe_adferias, feri_fl_periodo_ativo,
feri_dt_programacao, feri_dt_autorizacao, feri_tp_programacao,
feri_fl_adiantamento_durante, feri_fl_13_durante )
VALUES (#{auditDate, typeHandler="br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"}, #{auditUser}, #{auditStatus}, #{userCode},
#{currentYear}, #{sequencial}, #{initialPeriod}, #{finalPeriod},
#{status}, #{paymentStatus}, #{note}, #{advance13th}, #{paymentDate},
#{statusAuthorized}, #{additional}, #{activePeriod}, #{scheduleDate},
#{authorizationDate}, #{typeProgramming}, #{advanceVacation},
#{advance13thVacation} )
</insert>
mybatis-config.xml
<typeHandlers>
<typeHandler javaType="org.joda.time.DateTime" jdbcType="DATE" handler="br.gov.df.terracap.grh.util.DateTimeTypeHandler"/>
<typeHandler javaType="org.joda.time.LocalDateTime" jdbcType="TIMESTAMP" handler="br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"/>
</typeHandlers>
Error when test the Insert
### Error updating database. Cause:
org.apache.ibatis.builder.BuilderException: Error resolving class .
Cause: org.apache.ibatis.type.TypeException: Could not resolve type
alias '"br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"'.
Cause: java.lang.ClassNotFoundException: Cannot find class:
"br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler" ### Cause:
org.apache.ibatis.builder.BuilderException: Error resolving class .
Cause: org.apache.ibatis.type.TypeException: Could not resolve type
alias '"br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"'.
Cause: java.lang.ClassNotFoundException: Cannot find class:
"br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"
org.apache.ibatis.exceptions.PersistenceException
VALUES (#{auditDate, typeHandler="br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler"}
Correct:
VALUES (#{auditDate,
typeHandler=br.gov.df.terracap.grh.util.LocalDateTimeTypeHandler}
*without quotes

Resources