java调用mysql存储过程

一、背景

   在mysql上定义了存储过程,然后我想每1分钟调用一次存储过程。于是我设置了一个event,但是这个事件默认的运行周期为天,我尝试修改成minute却不生效。所以我决定通过java代码来调用存储过程。

二、mysql存储过程

CREATE DEFINER=`root`@`%` PROCEDURE `apporder`.`ord_shopping`()
begin
truncate table ord_shopping_procedure;
insert into   ord_shopping_procedure
select  * from  apporder.ord_shopping_order
union all 
select  * from  apporder.ord_shopping_order_2
union all 
select  * from  apporder.ord_shopping_order_3
union all 
select  * from  apporder.ord_shopping_order_4
union all 
select  * from  apporder.ord_shopping_order_5
union all 
select  * from  apporder.ord_shopping_order_6
union all 
select  * from  apporder.ord_shopping_order_7
union all 
select  * from  apporder.ord_shopping_order_8
union all 
select  * from  apporder.ord_shopping_order_9
union all 
select  * from  apporder.ord_shopping_order_10
union all 
select  * from  apporder.ord_shopping_order_11
union all 
select  * from  apporder.ord_shopping_order_12
union all 
select  * from  apporder.ord_shopping_order_13
union all 
select  * from  apporder.ord_shopping_order_14
union all 
select  * from  apporder.ord_shopping_order_15
union all 
select  * from  apporder.ord_shopping_order_16
union all 
select  * from  apporder.ord_shopping_order_17
union all 
select  * from  apporder.ord_shopping_order_18
union all 
select  * from  apporder.ord_shopping_order_19
union all 
select  * from  apporder.ord_shopping_order_20
union all 
select  * from  apporder.ord_shopping_order_21
union all 
select  * from  apporder.ord_shopping_order_22
union all 
select  * from  apporder.ord_shopping_order_23
union all 
select  * from  apporder.ord_shopping_order_24
union all 
select  * from  apporder.ord_shopping_order_25
union all 
select  * from  apporder.ord_shopping_order_26
union all 
select  * from  apporder.ord_shopping_order_27
union all 
select  * from  apporder.ord_shopping_order_28
union all 
select  * from  apporder.ord_shopping_order_29
union all 
select  * from  apporder.ord_shopping_order_30
union all 
select  * from  apporder.ord_shopping_order_31
union all 
select  * from  apporder.ord_shopping_order_32
union all 
select  * from  apporder.ord_shopping_order_33
union all 
select  * from  apporder.ord_shopping_order_34
union all 
select  * from  apporder.ord_shopping_order_35
union all 
select  * from  apporder.ord_shopping_order_36
union all 
select  * from  apporder.ord_shopping_order_37
union all 
select  * from  apporder.ord_shopping_order_38
union all 
select  * from  apporder.ord_shopping_order_39
union all 
select  * from  apporder.ord_shopping_order_40
union all 
select  * from  apporder.ord_shopping_order_41
union all 
select  * from  apporder.ord_shopping_order_42
union all 
select  * from  apporder.ord_shopping_order_43
union all 
select  * from  apporder.ord_shopping_order_44
union all 
select  * from  apporder.ord_shopping_order_45
union all 
select  * from  apporder.ord_shopping_order_46
union all 
select  * from  apporder.ord_shopping_order_47
union all 
select  * from  apporder.ord_shopping_order_48
union all 
select  * from  apporder.ord_shopping_order_49
union all 
select  * from  apporder.ord_shopping_order_50
union all 
select  * from  apporder.ord_shopping_order_51
union all 
select  * from  apporder.ord_shopping_order_52
union all 
select  * from  apporder.ord_shopping_order_53
union all 
select  * from  apporder.ord_shopping_order_54
union all 
select  * from  apporder.ord_shopping_order_55
union all 
select  * from  apporder.ord_shopping_order_56
union all 
select  * from  apporder.ord_shopping_order_57
union all 
select  * from  apporder.ord_shopping_order_58
union all 
select  * from  apporder.ord_shopping_order_59
union all 
select  * from  apporder.ord_shopping_order_60
union all 
select  * from  apporder.ord_shopping_order_61
union all 
select  * from  apporder.ord_shopping_order_62
union all 
select  * from  apporder.ord_shopping_order_63;truncate table ord_shopping;
insert into   ord_shopping
select t.*, JSON_EXTRACT(t.json, '$.skuName') as sku_name from  (
select id,order_type,order_mode,user_id,user_name,trade_no,state,total_amount, pay_amount, pay_time ,
ou_name ,mobile  ,create_time, sale_amount, JSON_EXTRACT(item_abstract_json, '$[0]') as json,store_ou_code,store_name
,mch_ou_code,mch_name,pay_mode
from  ord_shopping_procedure ) t;truncate table ctg_h5_pay_order;
insert into  ctg_h5_pay_order 
select  id as order_no , 
total_amount as total_price ,
pay_time,
trade_no,
trade_no as pay_no,
mobile as phone,
store_ou_code as store_code ,
store_name,
sku_name as product_id ,
user_id ,
case 
when state = '1' then '未支付'
when state = '2' then '支付中'
when state = '3' then '已支付'
when state = '7' then '废弃'
when state = '8' then '已失效'
end
state,
create_time,
pay_mode,
case 
when state = '1' then '未支付'
when state = '2' then '支付中'
when state = '3' then '已支付'
when state = '7' then '废弃'
when state = '8' then '已失效'
endtrade_status
from  ord_shopping;END

我定义的event,其他定时执行存储过程

CREATE EVENT ord_shopping_event
ON SCHEDULE EVERY 1 DAY
STARTS '2023-11-28 04:51:22.000'
ON COMPLETION PRESERVE
ENABLE
DO call ord_shopping()

但是 ON SCHEDULE EVERY 1 DAY 我改为 ON SCHEDULE EVERY 1 MINUTE 却修改不了。

于是我使用java来调用存储过程

三、通过java来调用存储过程

在 接口中定义

@Repository
public interface TransactionMapper extends BaseMapper<Transaction>{

    /**
     * 调用存储过程
     */
    @Select("<script>" + "call ord_shopping() "
            + "</script>")
    public  void callOrdShopping();

}

	/*** 调用存储过程*/@Select("<script>" + "call ord_shopping() "+ "</script>")public  void callOrdShopping();

通过service调用

    
    /**
     * 调用存储过程
     */
    public void callOrdShopping() {
        
        transactionMapper.callOrdShopping();
    }
 

	/*** 调用存储过程*/public void callOrdShopping() {transactionMapper.callOrdShopping();}

通过定时任务调用

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class ToolServiceThread implements ApplicationRunner {

 
    @Autowired
    private TransactionService transactionService;
 
    /**
     * 交易信息上链定时任务 早上2点10分
     */
    // @Scheduled(cron = "0 10 2 * * ?")
    @Scheduled(cron = "0 0/1 * * * ?")
    public void callOrdShopping() throws Exception {
        log.info("调用交易信息存储过程");
        transactionService.callOrdShopping();
    }
    
     
}
 

	/***  1分钟调用一次*/// @Scheduled(cron = "0 0/1 * * * ?")public void callOrdShopping() throws Exception {log.info("调用交易信息存储过程");transactionService.callOrdShopping();}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/189770.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

cpu版本的torch可以用清华镜像源安装

一、来到pytroch官网找到如下代码 官方提供的默认的安装cpu版本的torch的命令 pip3 install torch torchvision torchaudio二、使用清华镜像安装 pip3 install torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple

深入探究Alibaba Druid:Java界的数据库连接池巨人

深入探究Alibaba Druid&#xff1a;Java界的数据库连接池巨人 引言 在现代企业级应用开发中&#xff0c;数据库连接池是不可或缺的组件之一。它们负责降低数据库操作的延迟&#xff0c;提高性能&#xff0c;并且能有效管理数据库连接资源。在众多数据库连接池中&#xff0c;A…

1292:宠物小精灵之收服

【算法分析】 该问题为二维费用背包。精灵球数量、皮卡丘体力值都是费用。 题目说&#xff0c;如果一个野生小精灵让皮卡丘的体力小于等于0&#xff0c;那么无法收服该小精灵。也就是说当皮卡丘有m点体力时&#xff0c;最多可以消耗的体力为m-1点。在输入m后&#xff0c;先让…

自然语言处理 (NLP) 中的组合语义分析

埃弗顿戈梅德&#xff08;Everton Gomede&#xff09; 一、介绍 自然语言处理 &#xff08;NLP&#xff09; 中的组合语义分析是一个引人入胜且复杂的话题。为了充分理解它&#xff0c;将这个概念分解成它的基本组成部分是至关重要的&#xff1a;组合语义及其在NLP中的应用。组…

零售数字化“逆熵”的6项原则和8种能力建设|ShopeX徐礼昭

作者&#xff1a;徐礼昭 来源&#xff1a;《三体零售逆熵法则》节选 旧的规则与秩序被打破&#xff0c;无序成为常态 新时代洪流裹挟冲击着传统零售 无序带来的“熵增”侵蚀企业生命 所有人都在不确定性中寻找确定 数字化如何助力企业铸就「反熵增」神器&#xff1f; 如何…

uniapp设置手机通知权限以及uniapp-push2.0推送

unipush2.0代码 export default function () {// 调用获取用户通知权限setPermissions()// 获取客户端唯一的推送标识&#xff0c;可用于测试uni.getPushClientId({success: (res) > {console.log(res.cid)},fail(err) {console.log(err)}})// 监听推送uni.onPushMessage(r…

设计模式之美学习笔记-单例模式-为什么说支持懒加载的双重检测不比饿汉式更优?

单例设计模式&#xff1a;一个类只允许创建一个对象&#xff08;或者实例&#xff09;&#xff0c;那这个类就是一个单例类&#xff0c;这种设计模式就叫作单例设计模式&#xff0c;简称单例模式。 实战案例一&#xff1a;处理资源访问冲突 我们先来看第一个例子。在这个例子…

第十节HarmonyOS 常用基础组件-Image

一、组件介绍 组件&#xff08;Component&#xff09;是界面搭建与显示的最小单位&#xff0c;HarmonyOS ArkUI声名式为开发者提供了丰富多样的UI组件&#xff0c;我们可以使用这些组件轻松的编写出更加丰富、漂亮的界面。 组件根据功能可以分为以下五大类&#xff1a;基础组件…

VB.NET二维数组的组合

缘由https://bbs.csdn.net/topics/397512167 首先写了自上而下的查找&#xff0c;在此基础上再加逻辑控制以达到目标。 Sub 四维组合()Dim wei4 {{4, 5, 6, 7}, {1, 2, 4, 8}, {9, 10, 11, 12}, {3, 13, 21, 22}}Dim j 1, h 0, f 0, zc wei4(0, f)Dim sc ""Whi…

xss漏洞后端进行html消毒

import org.jsoup.Jsoup;public static String sanitizeHtml(String input) {// 使用 Jsoup 消毒 HTMLreturn Jsoup.clean(input, Safelist.relaxed());}public static void main(String[] args) {String userInput "<p><script>alert(1)</script>Safe…

海外IP罗拉rola正版去哪里找?

免费海外IP代理能用吗&#xff1f;和收费的有哪些差异&#xff1f; 如今在这个大数据时代&#xff0c;无论你从事哪个行业&#xff0c;都离不开数据&#xff0c;尤其是做跨境电商的&#xff0c;更一步都离不开海外IP代理&#xff0c;无论是网站引擎优化还是营销推广、数据抓取…

LeetCode105.从前序和中序遍历序列构造二叉树

这道题看完题想了几分钟就想到大概的思路了&#xff0c;但是在写的时候有很多细节没注意出了很多问题&#xff0c;然后写了1个多小时&#xff0c;其实这道题挺简单的。 首先&#xff0c;最基本的知识&#xff0c;先序遍历是根左右&#xff0c;中序遍历是左根右&#xff0c;那么…

集简云语聚AI新增模型测试,支持多模型同时进行交互,快速评估不同模型性能

语聚AI模型测试 在ChatGPT爆火的推动下&#xff0c;由生成式 AI 掀起的全球人工智能新浪潮就此拉开了序幕&#xff0c;人工智能也成为越来越多企业提升业务效率、优化业务流程的首选方案。 然而&#xff0c;面对层出不穷的AI模型&#xff0c;每个模型在完善度、功能性、易用性…

【算法每日一练]-图论(保姆级教程篇10 并查集)#POJ1988 #POJ1182

目录 POJ1988 思路&#xff1a; POJ1182 思路&#xff1a; POJ1988 有n个栈每个栈中有一个方块&#xff0c;现要执行n次操作。一种是移数&#xff0c;一种是计数 移数M&#xff1a;把包含x的栈整体移动到y栈顶 计数C&#xff1a;统计X方块下面的方块数 输入&#xff1a; 6 …

Pandas进阶:分类数据处理

引言 category是pandas的一种分类的定类数据类型。和文本数据.str.<methond>一样&#xff0c;它也有访问器功能.cat.<method>。 本文将介绍&#xff1a; 什么是分类数据&#xff1f; 分类数据cat的处理方法 为什么要使用分类数据&#xff1f; 分类数据cat使用…

Vue系列:页面中图片等静态资源引用

前言 近期在做项目时遇到一些图片、视频、动态图片等静态资源的使用&#xff0c;在vue页面jsx、tsx中使用的时候遇到些问题&#xff1b; 对静态资源的引用使用总结如下 引入方式说明 以下代码实例以图片、vue环境为例&#xff0c;不放视屏等引入实例&#xff0c;视频使用方式…

C++标准模板(STL)- 类型支持 (杂项变换,定义适于用作给定大小的类型的未初始化存储的类型,std::aligned_storage)

类型特性 类型特性定义一个编译时基于模板的结构&#xff0c;以查询或修改类型的属性。 试图特化定义于 <type_traits> 头文件的模板导致未定义行为&#xff0c;除了 std::common_type 可依照其所描述特化。 定义于<type_traits>头文件的模板可以用不完整类型实…

记录5款NodeJS后端框架

文章目录 前言一、Express二、Nest.js三、Meteor四、Koa.js五、Fastify 前言 https://xie.infoq.cn/article/d8c2cd9cb99a04cbbf0a45434 https://juejin.cn/post/6959583458779725860 Nodejs 框架分为三种类型&#xff1a; MVCREST APIFull-Stack 一、Express Express 是最…

uni-app 微信小程序 电子签名及签名图片翻转显示功能

文章目录 1. 需求背景2. 开始撸2.1 点击 重写 进入签名页面&#xff08;上图一&#xff09;2.2 书写签名&#xff0c;点击确认返回&#xff0c;及图片翻转显示&#xff08;上图二&#xff0c;三&#xff09; 3. 图片进行翻转&#xff0c;返回翻转后的图片 1. 需求背景 接的一个…

Hdoop学习笔记(HDP)-Part.6 安装OracleJDK

六、安装OracleJDK 下载jdk安装文件&#xff0c;放到/opt中&#xff0c;将文件解压到/usr/local下后&#xff0c;修改/etc/profile文件中环境参数&#xff0c;实现java的安装。 创建jdk.yml文件 ---- hosts: alltasks:- name: copy and unzip jdkunarchive:src: "/opt/j…