spring+mybatis 中使用Spring的JdbcTemplate调用Oracle的存储过程


最近公司项目需要在同步实时数据时(逻辑客户数据-中间库-系统的数据库),先把客户的数据同步到中间数据库中,

因此使用了存储过程来实现这一需求:

无返回参数的存储过程定义和调用:

oracle中定义

create or replace procedure sd_middata_kc is
begin
 update TSTKLSKC set comflag=0 where comflag=1 and orgcode='2018';
commit;

end sd_middata_kc;


oracle中:执行存储过程

begin
  -- Call the procedure
  sd_middata_kc;
end;



java代码中执行存储过程:


getSyncJdbcTemplate方法是获取jdbcTemplate的方法实例,主要使用execute来执行存储无参数过程 sd_middate_kc(存储过程名)(! {} 一定要带)

下面是在实现中碰到的坑,

错误日志:


SQLErrorCod loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]

19:13:35.950 [pool-4-thread-1] DEBUG o.s.j.support.SQLErrorCodesFactory - Looking up default SQLErrorCodes for DataSource [org.apache.commons.dbcp.BasicDataSource@7c38c7f6]
19:13:35.952 [pool-4-thread-1] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
19:13:35.956 [pool-4-thread-1] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
19:13:35.961 [pool-4-thread-1] DEBUG o.s.j.support.SQLErrorCodesFactory - SQL error codes for 'Oracle' found
19:13:35.961 [pool-4-thread-1] DEBUG o.s.j.support.SQLErrorCodesFactory - Caching SQL error codes for DataSource [org.apache.commons.dbcp.BasicDataSource@7c38c7f6]: database product name is 'Oracle'
19:13:35.961 [pool-4-thread-1] DEBUG o.s.j.s.SQLErrorCodeSQLExceptionTranslator - Translating SQLException with SQL state '65000', error code '6550', message [ORA-06550: 第 1 行, 第 7 列: 
PLS-00201: identifier 'SD_MIDDATA_KC' must be declared
ORA-06550: 第 1 行, 第 7 列: 
PL/SQL: Statement ignored
]; SQL was [ {call sd_middata_kc}] for task [StatementCallback]
19:13:35.963 [pool-4-thread-1] ERROR com.hy.lamp.quartz.task.RunTask - StatementCallback; bad SQL grammar [ {call sd_middata_kc}]; nested exception is java.sql.SQLException: ORA-06550: 第 1 行, 第 7 列: 
PLS-00201: identifier 'SD_MIDDATA_KC' must be declared
ORA-06550: 第 1 行, 第 7 列: 
PL/SQL: Statement ignored


org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [ {call sd_middata_kc}]; nested exception is java.sql.SQLException: ORA-06550: 第 1 行, 第 7 列: 
PLS-00201: identifier 'SD_MIDDATA_KC' must be declared
ORA-06550: 第 1 行, 第 7 列: 
PL/SQL: Statement ignored
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:419) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:443) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at com.hy.lamp.quartz.task.external.DataRealSyncExecuter.execute(DataRealSyncExecuter.java:40) ~[hy-lamp-service-1.0.0.0-SNAPSHOT.jar:na]
at com.hy.lamp.quartz.task.RunTask.run(RunTask.java:44) ~[hy-lamp-service-1.0.0.0-SNAPSHOT.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_45]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
Caused by: java.sql.SQLException: ORA-06550: 第 1 行, 第 7 列: 
PLS-00201: identifier 'SD_MIDDATA_KC' must be declared
ORA-06550: 第 1 行, 第 7 列: 

PL/SQL: Statement ignored



经排查发现是配置文件中,oracle的的用户密码不对,写成了另外一个ocacle库的用户和密码,以后码友们,碰到此类问题可以从这方面入手排查。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值