SQuirrel Call Stored Procedure - stored-procedures

I am trying to call a DB2 stored procedure from Squirrel.
I can call the stored procedure successfully from the DB2 command line
processor.
CALL PIPPOOWN.PIPPO
('04','prov','0001','provprov')
I append ;retrieveMessagesFromServerOnGetMessage=true; to connection string for the database.
jdbc:db2://xx.xx.x.xx:50001/DB2XYX:retrieveMessagesFromServerOnGetMessage=true;
But when I try this in Squirrel I get this error message. I am running
Error: [jcc][10413][10940][4.19.49]
Analisi della sostituzione letterale non riuscita per la chiamata della procedura a DB2 per z/OS.
Testo SQL non riuscito CALL
SP_XXXXX('XX','prova').
ERRORCODE=-4463, SQLSTATE=42601
SQLState: 42601
ErrorCode: -4463
2021-02-02 12:01:03,409 [Thread-6] ERROR net.sourceforge.squirrel_sql.fw.util.DefaultExceptionFormatter - Exception occurred while formatting: null
java.lang.NullPointerException
at net.sourceforge.squirrel_sql.plugins.db2.DB2JCCExceptionFormatter.format(DB2JCCExceptionFormatter.java:93)
at net.sourceforge.squirrel_sql.fw.util.DefaultExceptionFormatter.format(DefaultExceptionFormatter.java:68)
at net.sourceforge.squirrel_sql.client.session.Session.formatException(Session.java:1195)
at net.sourceforge.squirrel_sql.client.session.mainpanel.SQLExecutionHandler.sqlExecutionException(SQLExecutionHandler.java:458)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.handleError(SQLExecuterTask.java:621)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.runDirect(SQLExecuterTask.java:264)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.run(SQLExecuterTask.java:137)
at net.sourceforge.squirrel_sql.fw.util.TaskExecuter.run(TaskExecuter.java:82)
at java.lang.Thread.run(Unknown Source)
i updated jdbc drivers but i didn't fix.
DB2 Version: 11.01
If I use IBM DATA STUDIO or I use a DB2 AIX it works.
EDIT 03/02/2021
I downloaded "IBM Data Server Driver for JDBC and SQLJ (JCC Driver)" Version 11.5.4, then I configured it to use db2jcc4.jar
Now it gives the following error:
NO AUTHORIZED PROCEDURE NAMED PIPPOOWN.PIPPO HAVING COMPATIBLE ARGUMENTS WAS FOUND.
SQLCODE=-440, SQLSTATE=42884, DRIVER=4.26.14 SQL Code: -440, SQL State: 42884
but if i use IBM DATA STUDIO with the same user and statements i get no error
Stored Procedure "PIPPO" - GRANT
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO "ALL";
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO "PUBLICB";
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO "PIPPOOWN" WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO "USERWEB";
GRANT EXECUTE ON PROCEDURE "PIPPOOWN"."PIPPO" TO PUBLIC;
Stored Procedure "PIPPO" - Distribution Options (using Data Studio)
CURRENT_PATH BY SQUIRREL
SELECT CURRENT_PATH FROM SYSIBM.SYSDUMMY1
RESULTS
-----------------------------------------------
"SYSIBM","SYSFUN","SYSPROC","SYSIBMADM","PIPPOOWN"
Finally, I can't find any error in the Squirrel log.
Any ideas?
EDIT 04/02/2021
I excecute the call statement on Squirrel, enabling the JDBC log and I found this error:
[jcc][Time:2021-02-04-10:16:23.549][Thread:Thread-4][Statement#f7f204]**execute (CALL OWNER1.SP_ABC('xx')) called**
[jcc][Time:2021-02-04-10:16:23.549][Thread:Thread-4][Statement#f7f204]stmt_bidiTransform (CALL OWNER1.SP_ABC('xx')) called
[jcc][Time:2021-02-04-10:16:23.549][Thread:Thread-4][Statement#f7f204]**stmt_bidiTransform not enabled (CALL OWNER1.SP_ABC('xx')) called**
[jcc][t4][time:2021-02-04-10:16:23.549][Thread:Thread-4][tracepoint:1][Request.flush]
[jcc][t4] SEND BUFFER: EXCSQLSTT (ASCII) (EBCDIC)
...
.....
**com.ibm.db2.jcc.am.SqlSyntaxErrorException
** at com.ibm.db2.jcc.am.b7.a(b7.java:810)
at com.ibm.db2.jcc.am.b7.a(b7.java:66)
at com.ibm.db2.jcc.am.b7.a(b7.java:140)
at com.ibm.db2.jcc.am.k4.b(k4.java:2471)
at com.ibm.db2.jcc.am.k4.c(k4.java:2452)
at com.ibm.db2.jcc.t4.ab.n(ab.java:914)
at com.ibm.db2.jcc.t4.ab.f(ab.java:156)
at com.ibm.db2.jcc.t4.p.e(p.java:81)
at com.ibm.db2.jcc.t4.av.k(av.java:175)
at com.ibm.db2.jcc.am.k4.ao(k4.java:2413)
at com.ibm.db2.jcc.am.k4.a(k4.java:3383)
at com.ibm.db2.jcc.am.k4.e(k4.java:1131)
at com.ibm.db2.jcc.am.k4.execute(k4.java:1110)
at net.sourceforge.squirrel_sql.client.session.StatementWrapper.execute(StatementWrapper.java:168)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.processQuery(SQLExecuterTask.java:361)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.runDirect(SQLExecuterTask.java:214)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.run(SQLExecuterTask.java:137)
at net.sourceforge.squirrel_sql.fw.util.TaskExecuter.run(TaskExecuter.java:82)
at java.lang.Thread.run(Unknown Source)
For comparing the different logs, I also activate the IBM DATA STUDIO JDBC log (where the CALL statements work correctly) and I noticed that a prepareCall() is done before executing execute().
IBM DATA STUDIO
[jcc][Time:2021-02-03-20:52:10.381][Thread:Worker-19][Connection#97f8a03c]prepareCall (CALL OWNER1.SP_ABC('XX')) called
[jcc] [time:2021-02-03-20:52:10.383][Thread:Worker-19][tracepoint:4000]LiteralInfo entry,sql:CALL OWNER1.SP_ABC('XX')
[jcc] [time:2021-02-03-20:52:10.387][Thread:Worker-19][tracepoint:4005]LiteralInfo.return,OriginalSQL:CALL OWNER1.SP_ABC('XX'), modifiedSQL:CALL OWNER1.SP_ABC(?), literalCount=1, parmCount=1[CHARACTER(XX)]
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][Connection#97f8a03c]prepareCall () returned MappedCallableStatement#691cf97[com.ibm.db2.jcc.am.CallableStatement#88958c83]
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][Connection#97f8a03c]prepareCall () returned MappedCallableStatement#691cf97[com.ibm.db2.jcc.am.CallableStatement#88958c83]
[jcc][Thread:Worker-19][SystemMonitor:stop] core: 9.5471ms | network: 0.0ms | server: 0.0ms
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]setMaxRows (0) called
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]setString (1, XX) called
[jcc][Thread:Worker-19][SystemMonitor:start]
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]execute () called
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]stmt_bidiTransform (CALL OWNER1.SP_ABC(?)) called
[jcc][Time:2021-02-03-20:52:10.390][Thread:Worker-19][CallableStatement#88958c83]stmt_bidiTransform not enabled (CALL OWNER1.SP_ABC(?)) called
[jcc][t4][time:2021-02-03-20:52:10.390][Thread:Worker-19][tracepoint:1][Request.flush]
I looked in the [IBM documentation][4] and it seems that in order to call SP with parameters in the Z/OS environment, it is necessary to perform a PreparedStatement.
At this point I think it’s a Squirrel BUG...

I tried to open a BUG: squirrel-sql:bugs#1457 Call Stored Procedure with input parameters on DB2 z/os

Related

Can I call a postgres "Procedure" (not "function") from java using the postgres JDBC driver?

I'm new to postgres but am attempting to call a procedure in Postgres 11 (new "procedure" not a "function"), calling from java as a spring SimpleJDBCCall (using Postgresql-42.2.5 jdbc driver). However, when I execute the procedure I am encountering the following exception:
org.springframework.jdbc.BadSqlGrammarException:
CallableStatementCallback; bad SQL grammar [{call
pa_test_schema.pr_dosomething(?)}]; nested exception is
org.postgresql.util.PSQLException: ERROR:
pa_test_schema.pr_dosomething(bigint) is a procedure Hint: To call a
procedure, use CALL. Position: 15 at
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1402)
at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1065)
at
org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1104)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:414)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:397)
at
org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:193)
My procedure code:
CREATE PROCEDURE pa_test_schema.pr_DoSomething
( P_input_ID IN inputs.input_ID%TYPE
) AS $$
BEGIN
-- do something
END;
$$ LANGUAGE plpgsql;
My java code:
SimpleJdbcCallOperations pr_DoSomething = new SimpleJdbcCall(jdbcTemplate)
.withSchemaName("pa_test_schema")
.withProcedureName("pr_DoSomething");
Map<String, Object> inputs = Maps.newHashMap();
inputs.put("p_input_id", 123456);
pr_DoSomething.execute(inputs);
When I step through the code I can see the driver is modifying the sql of the callable statement to the syntax required for calling a postgres function:
select * from pa_test_schema.pr_dosomething(?) as result
This is the method in the driver that is doing this conversion:
https://github.com/pgjdbc/pgjdbc/blob/faab499853c56f67cb70fb242f75b918452f2a6f/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L766
I understand procedures were only introduced in Postgres 11 (previously one would have used void-returning functions) and have read through the postgres driver documentation but don't see any reference to calling procedures rather than functions.
Does this mean that the current postgres driver does not yet support this or is there another approach I should be using? Should I just be using postgres functions instead?
Currently (as of Postgres 11.1 and driver version 42.2.5) the standard JDBC approach using a CallableStatement cannot be used to call a stored procedure.
I don't really use Spring JDBC Template, but the following code works in plain JDBC and should be adaptable to Spring JDBC Tempalte:
Connection con = DriverManager.getConnection(...);
PreparedStatement pstmt = con.prepareStatement("call pa_test_schema.pr_DoSomething(?)");
pstmt.setInt(1, 42);
pstmt.execute();
Note that this uses Postgres' call command. Do not confuse this with the "{call ...}" syntax for a CallableStatement.
Some more details on why currently a CallableStatement does not work can be found in the JDBC mailing list here and here

Neo4j apoc procedures impala configuration

1) Downloaded the impala drivers 2.5.37 from
https://www.cloudera.com/downloads/connectors/impala/jdbc/2-5-37.html
2) Executed:
call apoc.load.driver("com.cloudera.impala.jdbc4.Driver")
No errors.
3) Executed:
CALL apoc.load.jdbc("jdbc:impala://<URL>:21050/default;user=<username>;password=<password>",
'<database>.<table name>') YIELD row
RETURN row.account as account_num
Error :Failed to invoke procedure apoc.load.jdbc: Caused by:
java.lang.RuntimeException: Cannot execute SQL statement `SELECT *
FROM .. Error: [Simba]ImpalaJDBCDriver
Error setting/closing session: {0}.
Can you please help me out?
The second argument to apoc.load.jdbc must be a string that is either a table name or a SQL statement. Replace '.' with the appropriate value (in your case, probably the name of the table that contains the account column).

error calling stored procedure with output parameter in groovy

...... I found the reason - the problem was there was actually a select in a stored proc that was called from my stored proc which I didn't notice. After removing it everything worked fine.
I call a stored procedure from my code, it has one input and one output parameter. For some reason it gives me an exception, not sure what the problem is, here is the code:
int fileNumber
sql.call("{call initIMAGINE_IDENTIFIERS_DELTAS(?, ?)}", [type, Sql.INTEGER]){ number ->
fileNumber = number
}
and here is the declaration of stored proc:
create procedure initIMAGINE_IDENTIFIERS_DELTAS
#reportType varchar(30) = '',
#loop_id int output
as
BEGIN
the error I get:
Oct 30, 2014 11:18:16 AM groovy.sql.Sql callWithRows
WARNING: Failed to execute: {call initIMAGINE_IDENTIFIERS_DELTAS(?, ?)} because: Output parameters have not yet been processed. Call getMoreResults().
Caught: java.sql.SQLException: Output parameters have not yet been processed. Call getMoreResults().
java.sql.SQLException: Output parameters have not yet been processed. Call getMoreResults().
at net.sourceforge.jtds.jdbc.ParamInfo.getOutValue(ParamInfo.java:159)
at net.sourceforge.jtds.jdbc.JtdsCallableStatement.getOutputValue(JtdsCallableStatement.java:124)
at net.sourceforge.jtds.jdbc.JtdsCallableStatement.getObject(JtdsCallableStatement.java:315)
at Test.init(SqlConnection.gy:26)
at Test$init.call(Unknown Source)
at SqlConnection.run(SqlConnection.gy:9)
The same code actually works against Sybase 15.1 in 12.5 compatibility mode but doesn't work against Sybase 15.7. I am using jtds 1.3.1 driver.

Diagnosing Worklight 6 SQL Adapter issue, JPA tracing

Worklight Studio 6, SQL adapter attempting connection to DB2 database.
Standard pattern for procedure
return WL.Server.invokeSQLStatement({
preparedStatement : listUnassignedWorkOrders,
parameters : []
});
When I invoke my procedure I see this error
[ERROR ] FWLSE0035E: Invocation of procedure 'SqlStatement' failed.
[project Infrabel01] Type 'Function' currently does not support
marshalling to JSON.
And the logs show
[err] 0 WorklightPU WARN [Scheduled Executor-thread-1]
openjpa.Runtime - An error occurred while registering a
ClassTransformer with PersistenceUnitInfo: name 'WorklightPU', root
URL
[file:/C:/djna-nobackup/Workspaces/WL6.0/01/WorklightServerConfig/shared/resources/worklight-jee-library-6.0.0.jar].
The error has been consumed. To see it, set your openjpa.Runtime log
level to TRACE. Load-time class transformation will not be available.
How to diagnose? How would I set the trace level in worklight?
JPA docs say:
property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO,
Tool=INFO, SQL=TRACE"
But where to put that in worklight?
The WorklightPU WARN in the log is not relevant and has been removed in newer releases of Worklight.
For your actual issue, see the following developerWorks threads with the same issue that was resolved.
Type 'Function' currently does not support marshalling to JSON.
developerWorks thread #1
developerWorks thread #2

Unable to retrieve destination column descriptions from the parameters of the SQL command

I am trying to upgrade an SSIS package from 2008 to 2012 and getting the below error.
Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has
occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Server Native
Client 11.0" Hresult: 0x80004005 Description: "The metadata could
not be determined because statement 'EXEC master.dbo.xp_logevent
#ErrorCode, #Message, error' in procedure 'DebugPrint' invokes an
extended stored procedure.".
Error: Unable to retrieve destination column descriptions from the
parameters of the SQL command.
Basically, we have an OLE DB Command to call a stored procedure which call several (nested) stored procedures and one of it is DebugPrint which call master.dbo.xp_logevent. Any idea to fix it? It works in SSIS 2008.
Thanks
You could try using 'with result sets' when calling your proc and setting your metadata there.
Example :
EXEC dbo.proc
WITH RESULT SETS (
ID INT
,Col2 VARCHAR)
I came across a similar error.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "The metadata could not be determined because statement '....' uses a temp table.".
Work around.
If SP uses a #table or ##table and it is used in the SP, then we need to specify the #table structure along with the EXEC.
The SP should be given along with the structure.
EXEC SP_TestTemp 1,2
it should be given like
EXEC SP_TestTemp 1,2 WITH RESULT SETS
(
(
id int,
Marks int
)
)
Note: the 'retain same connection = true' and 'validate external metadata' = false did not help/work here

Resources