java调用mysql存储过程

news2024/10/7 10:18:08

一、背景

   在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 '已失效'
end
 trade_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.coloradmin.cn/o/1276583.html

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

相关文章

排序算法:n个0~1000之间的整数,将他们从大到小排序

上榜理由&#xff1a; 如果没见过这种排序题&#xff0c;可能首先想到的就是常用的排序算法&#xff0c;比如快速排序&#xff0c;归并排序&#xff0c;那如果输入的n足够大&#xff0c;时间复杂度肯定比较高。其实题目0-1000的范围是一个题眼&#xff0c;所以一定有更优的排序…

将本地项目推送到github

欢迎大家到我的博客浏览。将本地项目推送到github | YinKais Blog 本地项目上传至 GitHub<!--more--> 1、进入项目根目录&#xff0c;初始化本地仓库 git init 2、创建密钥&#xff1a;创建 .ssh 文件夹&#xff0c;并进入 .ssh 文件夹 mkdir .ssh cd .ssh/ 3、生成…

海云安谢朝海:开发安全领域大模型新实践 人工智能助力高效安全左移

2023年11月29日&#xff0c;2023中国&#xff08;深圳&#xff09;金融科技大会成功举行&#xff0c;该会议是深圳连续举办的第七届金融科技主题年度会议&#xff0c;也是2023深圳国际金融科技节重要活动之一。做好金融工作&#xff0c;需要兼顾创新与安全&#xff0c;当智能体…

深入理解Docker容器核心技术

文章目录 1. Linux命名空间&#xff08;Namespaces&#xff09;1.1 示例&#xff1a;PID命名空间 2. 控制组&#xff08;cgroups&#xff09;2.1 示例&#xff1a;内存控制组 3. 联合文件系统&#xff08;UnionFS&#xff09;3.1 示例&#xff1a;查看镜像的分层结构 4. Docker…

ASP.NET Core 使用IIS调试出现505.24错误

最近一直再学习asp.net 相关的东西&#xff0c;主要是为前端app提供一个webapi接口。在使用iis调试程序时出现HTTP Error 500.24 - Internal Server Error错误&#xff0c;搞了好久才最终解决。 1.在项目中增加web.config配置文件 2.将配置文件改为如下内容 <?xml version…

MATLAB 模型参考自适应控制 - Model Reference Adaptive Control

系列文章目录 文章目录 系列文章目录前言一、参考模型二、扰动与不确定性模型三、直接 MRAC名义模型参数更新间接 MRAC估计器模型和控制器增益参数更新学习修正参考文献 前言 模型参考自适应控制模块计算控制动作&#xff0c;使不确定的受控系统跟踪给定参考被控对象模型的行为…

C# Serilog--可记录异常完整路径

1.Serilog安装 2.控制台代码 --设置日志记录器的最小级别为 Debug&#xff0c;即只记录 Debug 级别及以上的日志信息 --.WriteTo.File("logs\\log.txt", rollingInterval: RollingInterval.Day)&#xff1a;将日志信息写入到指定路径的文件中&#xff08;这里的路径…

企业真题(数组\面向对象-基础)

二、企业真题 1. 数组有没有length()这个方法? String有没有length()这个方法&#xff1f;&#xff08;*蓝&#xff09; 数组没有length()&#xff0c;是length属性。 String有length() 2. 有数组int[] arr&#xff0c;用Java代码将数组元素顺序颠倒&#xff08;闪*购&…

软件测试计划书

测试计划书 1.测试参考文档和测试提交文档 2.测试进度计划 3.测试资源 4.系统风险、优先级 5.测试策略 6.缺陷管理 7.测试停止标准 软件开发全文档下载进入主页。

linux后端基础---笔记整理(tmux、vim、shell、ssh/scp、git、thrift、docker)

目录 1.Linux常用文件管理命令 2.tmux终端复用器/vim命令式文本编辑器 3.Shell语法 3.1 Shell—版本3.2 新建一个test.sh文件3.3 Shell文件—运行方式3.4 Shell—注释3.5 Shell—变量3.6 Shell—默认变量&#xff0c;文件参数, “$”的用法3.7 Shell—数组3.8 shell—expr命令…

WebSocket 前端使用vue3+ts+elementplus 实现连接

1.配置连接 websocket.ts文件如下 import { ElMessage } from "element-plus";interface WebSocketProps {url: string; // websocket地址heartTime?: number; // 心跳时间间隔&#xff0c;默认为 50000 msheartMsg?: string; // 心跳信息&#xff0c;默认为pingr…

Edge 旧版本回退

微软官网 下载策略文件 下载后&#xff0c;解压打开 cad 包&#xff0c;把里面的 Windows\ADMX\ 下 3 个 *.admx 文件解压到 C:\Windows\PolicyDefinitions Windows\ADMX\zh-CN 下 3 个 *.adlm 文件解压到 C:\Windows\PolicyDefinitions\zh-CN Windows 搜索 gpedit&#xff…

水果软件FL Studio最新21.1.1.3750汉化版

FL Studio水果音乐编曲软件中文版,一款强大的音乐制作软件,可以进行音乐编曲、剪辑、录音、混音。FL Studio21.1.1.3750中文版是数字音频工作站 (DAW) 之一&#xff0c;日新月异。它是一款录音机和编辑器&#xff0c;可让您不惜一切代价制作精美的音乐作品并保存精彩的活动画廊…

分布式ID生成框架Leaf升级踩坑

背景&#xff1a; 在项目中需要一个统一的拿单号等唯一ID的服务&#xff0c;就想起了之前用到的leaf&#xff0c;但是因为项目要求&#xff0c;leaf的版本不符合&#xff0c;需要做一些升级 项目地址&#xff1a;https://github.com/Meituan-Dianping/Leaf 升级点&#xff1…

LangChain的函数,工具和代理(三):LangChain中轻松实现OpenAI函数调用

在我之前写的两篇博客中:OpenAI的函数调用,LangChain的表达式语言(LCEL)中介绍了如何利用openai的api来实现函数调用功能&#xff0c;以及在langchain中如何实现openai的函数调用功能&#xff0c;在这两篇博客中&#xff0c;我们都需要手动去创建一个结构比较复杂的函数描述变量…

【前端】-【electron】

文章目录 介绍electron工作流程环境搭建 electron生命周期&#xff08;app的生命周期&#xff09;窗口尺寸窗口标题自定义窗口的实现阻止窗口关闭父子及模态窗口自定义菜单 介绍 electron技术架构&#xff1a;chromium、node.js、native.apis electron工作流程 桌面应用就是…

SQL Server 2016(为数据表Porducts添加数据)

1、实验环境。 某公司有一台已经安装了SQL Server 2016的服务器&#xff0c;并已经创建了数据库PM。 2、需求描述。 在数据库PM中创建表products&#xff0c;"编号"列的值自动增长并为主键。然后使用T-SQL语句为表格插入如下数据。 3、实验步骤。 1、使用SSMS管理工…

2022年高校大数据挑战赛B题图像信息隐藏求解全过程论文及程序

2022年高校大数据挑战赛 B题 图像信息隐藏 原题再现&#xff1a; 互联网的快速发展&#xff0c;给图像、视频的传播方式带来巨大变化。图像作为媒体的重要载体&#xff0c;每天有大量的原创图像公开在互联网上&#xff0c;如何保护图像版权的同时不破坏原始的图像一直是图像处…

反转链表的实现

题目描述&#xff1a; 给出一个链表的头节点&#xff0c;将其反转&#xff0c;并返回新的头节点 思路1&#xff1a;反转地址 将每个节点里的地址由指向下一个节点变为指向前一个节点 定义三个结构体指针n1,n2,n3,n1表示改后指针的地址&#xff0c;n2表示要修改结构体里next的…

手机上的记事本怎么打开?安卓手机通用的记事本APP

有不少上班族发现&#xff0c;自己想要在电脑上随手记录一些工作文字内容&#xff0c;直接使用电脑上的记事本工具来编辑文字是比较便捷的。但是如果想要在手机上记录文字内容&#xff0c;就找不到手机上的记事本了。那么手机上的记事本怎么打开&#xff1f;安卓手机通用的记事…