I created a postgres function which returns a set of ref cursors. When I call the stored procedure from java the JDBC statement build is
select * from ga_rpt_movement('CODE','2018-5-10','2018-5-10','2018-5-10','C','STAT1','2018-5-10','2018-5-10','12344','A','T','34',25,50,'M','1','firstname',0,10) as result
When I run the same query on postgres terminal it gives me the four coursors.
Now I am not able to understand how do I fetch this cursor data in java.
Any suggestions, ideas are welcome and appreciated.
Result set when I run this query on postgres terminal look like this :
p_cr_personstatus
p_cr_identification
p_cr_phone
p_cr_count
(4 rows)
I am trying to implement this using spring JPA only.
Related
Using Java, I have built many CRUD applications but I need an idea of how to create an endpoint to invoke the procedure in TempDB -- for development I can create a small procedure in dev env and invoke it from java.
I am using SQL developer, Oracle database, and Java language. I tried to look at other docs as well but could not find any article related to that. Can anyone point me to the correct link?
UPDATE:
I wrote one simple stored procedure in SQL Developer. I get an error
ORA-01422: exact fetch returns more than requested number of rows
CREATE OR REPLACE PROCEDURE GETWORKFLOWINPUTRECORDS
IS
R_DATA reorg_automation_workflowinput%ROWTYPE;
BEGIN
SELECT * INTO R_DATA FROM reorg_automation_workflowinput where REORG_ID = 'S-CFO-FULL-65';
END GETWORKFLOWINPUTRECORDS;
When I run the below query, it gives only 1 result but in the procedure, I am getting the above error.
SELECT *
FROM reorg_automation_workflowinput
WHERE REORG_ID = 'S-CFO-FULL-65';
Let's resolve this issue and then we can move forward with building API for calling a stored procedure.
UPDATE 2
It is fetching empty result while running this procedure. Any suggestion on this?
create or replace PROCEDURE GETWORKFLOWINPUTRECORDS
AS
c1 SYS_REFCURSOR;
BEGIN
open c1 for
SELECT * FROM reorg_automation_workflowinput;
END GETWORKFLOWINPUTRECORDS;
Im saving data to myRepository1 and to be able to see the savings via the materialized view, i need to refresh it.
myRepository1.save(myObject);
myRepository2.refreshView();
myRepository2 has:
#Modifying
#Query(value = "BEGIN my_refresh_view(); END;", nativeQuery = true)
void refreshView();
Where my_refresh_view is a simple stored procedure.
This works fine in the real world (Oracle DB) - however, when i run my integration tests for the code above using an embedded h2 database, i get:
BEGIN my_refresh_view(); END; [42000-200]
org.springframework.dao.InvalidDataAccessResourceUsageException could not prepare statement;
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:281)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
Looks like the stored procedure and h2 dont match well together.
Any ideas how to make it work, or maybe there are workarounds?
Hibernate JPA (at least 5.0.0 and below) does not support stored procedures for H2Dialect.H2Dialect inherits Dialect.getCallableStatementSupport() which returns StandardCallableStatementSupport.NO_REF_CURSOR_INSTANCE. The standard callable statement support does not properly handle the H2 "out" parameter which is a Java return value and not a statement parameter
check details here
update account set lastusedval=lastusedval+1 where isactive=1 returning
lastusedval;
How to execute above query in java?
when i tried to execute in oracle its working but in java hibernate/jpa no way to store return value in update query.
By executing above query intention is to apply lock on db level when more than 1 request comes
Using jdbc prepared statement with registeroutparameter might help you to resolve this issue.
Creating an UPDATE RETURNING query in Hibernate
I have a query in Maximo which when run via DB visualizer runs fine. but the same query when I run in java via jdbc it throws sql exception.
The query is a bit different than usual and is shown below.
It gives the next sequence number for the next entry.
select nextval for mytabledseq from sysibm.sysdummy1
I have found the issue. I had to add the schema name before mytableseq.
e.g. MAXIMO.mytableseq now it works fine
I want to know how to run FileMaker(FMP pro) database command in java. I have got the connection to database,but not sure how to execute below query.
Get(AccountPrivilegeSetName)
ref:
http://www.filemaker.com/11help/html/func_ref2.32.4.html#1051898
You will need to add a calculation field in FileMaker to return as the result of the JDBC query. This is because you cannot call functions via JDBC, you can only retrieve field values.