Phenomenon
The user name for Db2,schema and access db is inconsistent.
The schema must be specified when the stored procedure is called, otherwise error.
Error code
Stored Procedures
SET SCHEMA = "QUOTATION"; SET CURRENT PATH = "SYSIBM","SYSFUN","SYSPROC","SYSIBMADM","DB2INST1"; CREATE PROCEDURE COPY_QUOTATION_TABLES (。。。。。。) BEGIN 。。。。。。 END; GRANT EXECUTE ON PROCEDURE "QUOTATION"."COPY_QUOTATION_TABLES"( VARCHAR(36), VARCHAR(36), INTEGER, TIMESTAMP, INTEGER, INTEGER ) TO USER "DB2INST1" WITH GRANT OPTION;
Mapper.xml
<update id="copyQuotationTables" statementType="CALLABLE" parameterType="map"> CALL COPY_QUOTATION_TABLES ( #{quotationId, jdbcType=VARCHAR, mode=IN} , #{newQuotationId, jdbcType=VARCHAR, mode=IN} , #{userId, jdbcType=INTEGER, mode=IN} , #{currentTime, jdbcType=TIMESTAMP, mode=IN} , #{reasonTypeFlag, jdbcType=INTEGER, mode=IN} , #{copyReason, jdbcType=INTEGER, mode=IN} ) </update>
Mapper.java
/** * Copy Quotation Tables * * @param param the parameter */ void copyQuotationTables(Map<String, Object> param);
Service.java
Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("quotationId", quotationId); paramMap.put("newQuotationId", newQuotationId); paramMap.put("userId", userId); paramMap.put("currentTime", currentTime); paramMap.put("reasonTypeFlag", 1); paramMap.put("copyReason", 1); Mapper.copyQuotationTables(paramMap);
Tomcat Context.xml
<Resource name="jdbc/testDS" auth="Container" type="javax.sql.DataSource" driverClassName="com.ibm.db2.jcc.DB2Driver" url="jdbc:db2://127.0.0.1:50000/test:currentSchema=QUOTATION;" username="db2inst1" password="db2inst1" maxActive="100" maxIdle="30"/>
Correct code
The Tomcat context.xml is appended with Currentfunctionpath.
<Resource name="jdbc/testDS" auth="Container" type="javax.sql.DataSource" driverClassName="com.ibm.db2.jcc.DB2Driver" url="jdbc:db2://127.0.0.1:50000/test:currentSchema=QUOTATION;currentFunctionPath=QUOTATION;" username="db2inst1" password="db2inst1" maxActive="100" maxIdle="30"/>
If you want to invoke a stored procedure in a DB tool (such as: Toda), but do not specify a schema,
such as: Call Copy_quotation_tables (...) )
You need to specify the current Path when you create a stored procedure
SET CURRENT PATH = "SYSIBM","SYSFUN","SYSPROC","SYSIBMADM","DB2INST1","QUOTATION";
Reason
DB2 stored Procedures (and functions) are not controlled by the current schema, but are controlled by current path.
DB2 does not specify schema call stored procedure failed sqlcode=-440, sqlstate=42884