Java.sql.SQLException: operation not allowed with Oracle procedure and mybatis - oracle

I am using Mybatis with springboot to connect with an Oracle database. In that process I need to update multiple fields in bulk.
I have created a procedure to implement that functionality on the database side. When calling that procedure from the DAO layer, the following exception occurs:
org.springframework.jdbc.UncategorizedSQLException:
Error getting generated key or setting result parameter object.
Cause
Java.sql.SQLException: operation not allowed.
<insert id="update" parameter="java.util.map" statement="callable">
{ call test.bulk_update_procedure(#{customerid, mode=IN , jdbcType= varchar},#{firstname, mode= IN, jdbcType= varchar},#{age,mode=IN, jdbcType=varchar})
</insert>

Related

Insert data in 2 tables MyBatis Error Command not properly ended

I´m trying to insert data in 2 tables, I have mybatis method with 2 single inserts but when I execute it it throws:
Error updating database. Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
Any idea?
solve using in mybatys method pl/sql
{call
declare
begin
end
}

Execute a stored procedure in Oracle from Azure Data Factory v2

I have a list of copy activities that are dynamically triggered in my ADF pipeline parallelly to load data from Azure SQL to Oracle 9i Database. I have a requirement to update a Status Table on Oracle if all my loads are completed successfully.
I tried multiple approaches provided in this community with no luck. Just wondering if I am missing anything. Any pointers please?
Approach 1 :
Create a SP on Oracle :
CREATE OR REPLACE PROCEDURE AZ.UPDATE_LOOKUP_TEST AS
BEGIN
update AZ.STATUS_DIM set Status='Completed' where Database ='NLM';
COMMIT;
END;
ADF:
Lookup Activty
Error details
Error code 2100
Failure type
User configuration issue
Details
ErrorCode=InvalidParameter,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=The value of the property 'columns' is invalid: 'Value cannot be null. Parameter name: columns'.,Source=,''Type=System.ArgumentNullException,Message=Value cannot be null. Parameter name: columns,Source=Microsoft.DataTransfer.Common,'
Approach 2 :
Query in Lookup Activity :
EXECUTE AZURE45.UPDATE_LOOKUP_TEST;
Error :
Failure happened on 'Source' side. ErrorCode=UserErrorOdbcOperationFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=ERROR [42000] [Microsoft][ODBC Oracle Wire Protocol driver][Oracle]ORA-00900: invalid SQL statement,Source=Microsoft.DataTransfer.ClientLibrary.Odbc.OdbcConnector,''Type=System.Data.Odbc.OdbcException,Message=ERROR [42000] [Microsoft][ODBC Oracle Wire Protocol driver][Oracle]ORA-00900: invalid SQL statement,Source=msora28.dll,'
Approach 3:
Directly provide the update statement in the Query
Query : update AZ.STATUS_DIM set Status='Completed' where Database ='NLM';
Error :
ErrorCode=InvalidParameter,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=The value of the property 'columns' is invalid: 'Value cannot be null. Parameter name: columns'.,Source=,''Type=System.ArgumentNullException,Message=Value cannot be null. Parameter name: columns,Source=Microsoft.DataTransfer.Common,'
How do I execute Oracle stored procedure from Azure datafactory?
Had a similar issue. Ended up being an issue with the ODBC driver that ADF is using. It requires a particular syntax.
The syntax I successfully used was:
CALL NAMEOFPACKAGE_PKG.NameOfFuntion()
which I called from a Script Activity

JPA error in merge: Password expired error if insert only

We are using entitymanager merge method to either update (if existing) or insert (if not existing) records in a certain table. What happens is if it is an update, there are no errors, but if it is insert, we see the following error from our logs:
Caused by: java.sql.SQLException: ORA-28001: the password has expired\n DSRA0010E: SQL State = 99999, Error Code = 28,001\n\tat oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)\n\tat oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:392)\n\tat oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:385)\n\tat oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:938)\n\tat oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:480)\n\tat oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:655
When we checked the datasource if connection successful - we get no password expired error.
We also tried manual insert to the table via oracle sql developer tool - no error
Can anyone advise why this is happening?

How to handle delete operation in spring if there are no record in database table?

I am using JdbcDaoSupport in DAO class for database coding in my project and there is a scenario for "deleting a member" from a table. I am using getJdbcTemplate.update("delete MEMBERINFO where memid= "+id); method. But if there is no data in the table, it doesn't raise any exception. The criteria is such that if there are no records in the table and yet user is trying to delete a record, then user will receive an error message saying "No data found". But for that, i need to raise an exception.
I am using oracle 11g XE.
Also same problem for getJdbcTemplate.query("select * from MEMBERINFO");
If there is no data it does not raise any exception.
Actually JdbcTemplate's update method returns int - number of rows was affected. All you need is to check amount of rows returned. If it's 0 the you can show an error message.
As for query it's fine that list is empty. If you need just one object use
queryForObject() method. It throws exception if no result is found.
BTW: The getJdbcTemplate.update("delete MEMBERINFO where memid= "+id); contains SQL injection. Use parameters instead.

Spring->Oracle stored procedure call schema issues

As part of a refactor, I am trying to change database calls to use Spring 4.1.0.RELEASE in order to handle connections and exceptions and allow result sets to be passed between functions and classes.
I've gotten my MS SQL Server stored procedure calls working fine, but when I tried to execute an Oracle stored procedure, I got the following error message:
2014-11-13 15:39:35,836 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /EmailServiceLayer/EmailServletClient/springtest/123:
org.jboss.resteasy.spi.UnhandledException: org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback;
bad SQL grammar [{call SPRING_JDBC_TEMPLATE_TEST()}]; nested exception is java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00201: identifier 'SPRING_JDBC_TEMPLATE_TEST' must be declared
I simplified the problem by writing a couple very simple stored procedures that write to a test table: one that takes a parameter and writes and one that takes no parameters and just writes a hardcoded value. These procedures are in the INV schema, which is the same user that my datasource is configured to use.
Eventually I tried running it on my own personal schema, using a datasource configured to use my personal credentials, and it succeeded. I had an admin grant execute all on the procedures in INV, but still no luck. I've confirmed that I can successfully execute simple inline inserts on the INV schema using Spring JdbcTemplate.execute().
My first attempts were using the JdbcTemplate with a CallableStatementCreator of my own definition. I then tried using SimpleJdbcCall, which is what I found out worked on my personal schema. Both ways give the same error message on the INV schema. Here is the code for my latest attempt:
SimpleJdbcCall caller = new SimpleJdbcCall(alex3InvTemplate).withProcedureName("spring_jdbc_template_test");
MapSqlParameterSource paramMap = new MapSqlParameterSource();
paramMap.addValue("p_testval", testval);
Map<String, Object> result = caller.execute(paramMap);
and my test proc:
create or replace
procedure spring_jdbc_template_test
(
p_testval IN number
)
as
begin
insert into jdbc_template_test_table values(p_testval);
commit;
end;
My application is running on a Wildfly 8.0.0.Final server. The datasource configurations for the 2 schemas are exactly the same except for the credentials used to log in. I am able to execute the procedures in INV using the same datasource with a basic JDBC CallableStatement and I've confirmed that I can run them in SQL Developer.
Thanks in advance for any help.
Turns out I made a silly mistake (typo) and was still using an old datasource and thus a different user than INV. Thanks to Dmitry for making me realize this. Still not sure why I'm unable to execute the procedure from a different user using the Spring framework when I was able to do so using a basic JDBC CallableStatement. It works with the INV datasource though and that's a satisfactory solution for me

Resources