Spring->Oracle stored procedure call schema issues - spring

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

Related

"The statement did not return a result set" on Create table (JDBC) [duplicate]

My original environment is SQL server 2005 + WebSphere v6.0(JDBC 3.0). When I run the program as below and it works well.
ResultSet rs=stmt.executeQuery(sql);
rs.next();
However, when I upgrade the environment to SQL server 2005 + WebSphere v8.5(JDBC 4.0), I get the error message:
com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not
return a result set.
From this forum's information, it seems that I have multiple resultsets, so I try to change the program as follows and it works fine.
stmt.execute(sql);
stmt.getMoreResults();
stmt.getMoreResults();
ResultSet rs=stmt.getResultSet();
rs.next();
My questions is that is there any approach that I can keep my program unchanged and works well with JDBC 4.0 driver(WAS v8.5) or any combination like SQL svr 2000 + WAS v8.5, etc.
Please give me any pointer and your recommendation is valuable to me, thank you.
Ann
You are attempting to execute a query that either produces multiple resultsets or that does not produce a resultset (eg UPDATE, INSERT etc) using executeQuery. The Javadoc for this method explicitly says:
Throws: SQLException - if a database access error occurs, this method is called on a closed Statement, the given SQL statement produces anything other than a single ResultSet object
You either need to use the executeUpdate method (if it is actually an update/insert/delete, or execute and then use the resulting boolean and that of getMoreResults() to decide how to proceed.

DB2 Problem inserting data in Stored Procedure

I need to insert data to 3 tables. I'm trying to use a SP. I know I could use Triggers instead but, for integrity reasons, I can't.
When I execute the INSERT statement in an independient Script, I works fine.
The problem is I'm trying to do the insert statement in the SP but it throws me
[SQL7008] error.
I don't know why it throws me this error only in the SP and not (using the same insert statement) in an independient script.
It's good to provide the DB2 version.
If it's DB2 for IBM i (aka iSeries, OS/400), then:
Received an SQL7008 error when attempting to INSERT data into an AS/400 table. "REXX variable '' contains inconsistent data".

Global temporary table throwing SQL Integrity constraint exception sometimes when invoking the stored proc

I'm trying to debug an error at work. It is using a stored procedure (in DB2) with a global temporary table to store and return back results. Consider the following code snippet inside the stored_proc
declare global temporary table session.details
(
row_count integer not null generated always as identity,
...
)
with replace on commit delete rows not logged on rollback delete rows;
The stored_proc itself is being called by Spring framework.
The bug is that sometimes (very often actually) when Spring invokes the stored_proc I see errors like
[FMWGEN][DB2 JDBC Driver][DB2]INSERT/UPDATE INVALID; INDEX 1 RESTRICTS COLUMNS WITH SAME VALUES;
nested exception is java.sql.SQLIntegrityConstraintViolationException:
[FMWGEN][DB2 JDBC Driver][DB2]INSERT/UPDATE INVALID; INDEX 1 RESTRICTS COLUMNS WITH SAME VALUES
Here is the java code snippet invoking this stored_proc
SqlParameterSource parameterSource = new MapSqlParameterSource().addValue("v_input", input)
Map<String, Object> result = proc.execute(parameterSource);
proc is an instance variable
private SimpleJdbcCall proc
this.proc =new SimpleJdbcCall(dataSource)
.withSchemaName("schema")
.withProcedureName("proc")
.declareParameters(
new SqlParameter("v_input", java.sql.Types.INTEGER)
).returningResultSet("output", new CustomRowMapper<String>());
According to IBM DB2 docs the Global Temporary Table gets destroyed and recreated for every session, but from the sql exception seems like that is not happening? Any help is appreciated.
Database sessions are bound to the connection. Assuming that you followed general guidelines for performance you have a connection-pool. Basically connections are reused and as such the session is never destroyed.

ORA-06508: PL/SQL: could not find program unit being called : "PUBLIC.PLITBLM"

I have a java web app that calls the oracle plsql procedure from ibatis xml file. this procedure captures the audit information of the table. so when multiple users modifies a table this stored procedure .after certain time i receive the following error.
--- The error occurred in example.xml.
--- The error occurred while applying a parameter map.
--- Check the example.params.
Check the statement (update procedure failed).
Cause: java.sql.SQLException: ORA-04068: existing state of packages has been discarded
ORA-04065: not executed, altered or dropped stored procedure "PUBLIC.PLITBLM"
ORA-06508: PL/SQL: could not find program unit being called:
"PUBLIC.PLITBLM" ORA-06512: at "AUDIT", line 279
ORA-06512: at line 1
call from ibatis
{call AUDIT(?,?,?,?,?,?,'val')}
call from java web app
Map _temp = new HashMap(params);
_temp.put("OPERATION_TYPE",operation);
sqlMapper.insert("call_proc_audit",_temp);
return false;
The plsql procedure has only execute immediate for insert,update and delete.
I have removed the code due to security.
The PLITBLM package is part of the standard Oracle build; apparently it handles index organized tables. It's not documented in any detail because it's not something we need to call directly. Find out more. It's likely that some standard Oracle functionality has dependencies on it.
As to why your program hurls that exception, that's a bit of a facer. The package is created by a script in the Oracle home $ORACLE_HOME/rdbms/admin/plitblm.sql. However, it cannot be run on its own but only as part of catproc,sql. This builds the data dictionary and other things, and is run as part of the Oracle installation process.
Perhaps you have a botched install?
Interestingly, the actual PLITBLM package is owned by SYS but the error message references PUBLIC, which suggests it might just be a missing public synonym. However, if catproc,sql has not run successfully there may be other lurking nasties. You really need a DBA to check the database, and if necessary re-run catproc,sql.

statements in jdbc

does statement object contain the session id the database returns for the current session? What does a resultset
contain?
To the best of my knowledge, no, Statements do not have session IDs. It seems like the Java API specifications for the Statement class backs that up. Basically, Statements are used to execute SQL statements by specifying a SQL query through the execute method.
A ResultSet is used to retrieve results which are returned by executing a query via a Statement or PreparedStatement.
The JDBC(TM) Database Access trail of The Java Tutorials contains some information on these topics. The following sections may be of interest:
Lesson: JDBC Basics
Updating Tables
Retrieving Values from Result Sets

Resources