Execution of a Java program by a trigger.「终于解决」

Execution of a Java program by a trigger.「终于解决」I want to make an update trigger execute a Java program. I have a table T1 with a column named Flag…

Execution of a Java program by a trigger.

I have a table T1 with a column named Flag. Whenever Flag changes, I want to run a trigger that results in an execution of a Java program.

Is this possible?

 

  •  答案

Yes, using the MySQL User-Defined Function (see MySQL 5.5 FAQ: Triggers) and installing the lib_mysqludf_sys

Then, for example, you can write your own trigger calling the sys_exec like this:

delimiter | CREATE TRIGGER testtrigger BEFORE UPDATE ON T1 FOR EACH ROW BEGIN DECLARE result int(10); IF NEW.Flag <> OLD.Flag THEN SET result = sys_exec("/path/to/javabin -jar your.jar"); -- other kind of works and checks... END IF; END; |

代码100分

The result contains the exit code of the external program

There are other useful functions in this library:

  • sys_eval : executes an arbitrary command, and returns it”s output.
  • sys_get : gets the value of an environment variable
  • sys_set : create an environment variable, or update the value of an existing environment variable
  • sys_exec : executes an arbitrary command, and returns it”s exit code

More info here

Try it on a dev env and…

Be very careful in deciding whether you need this function. UDFs are available to all database users – you cannot grant EXECUTE privileges for them. As the commandstring passed to sys_exec can do pretty much everything, exposing the function poses a very real security hazard.

But anyway, I agree with the proposal of Remus Rusanu

来源 分享

创建 09 4月. 13 Cristian Porta

how can i install the lib_mysqludf_sys utility ?? – Ankit Kapoor 09 4月. 13

Take a look into “installation” section here: https://github.com/mysqludf/lib_mysqludf_sys/blob/master/lib_mysqludf_sys.html … but in general read the mysql udf manual – Cristian Porta 09 4月. 13

getting this error —–CREATE FUNCTION sys_exec RETURNS INT SONAME “lib_mysqludf_sys.so”; ERROR 1126 (HY000): Can”t open shared library “lib_mysqludf_sys.so” (errno: 0 /usr/lib/mysql/plugin/lib_mysqludf_sys.so: wrong ELF class: ELFCLASS32) – Ankit Kapoor 10 4月. 13

do you have a 32bit or 64bit operating system? – Cristian Porta 10 4月. 13

its 64 bit ubuntu 0.12… – Ankit Kapoor 10 4月. 13

Try recompiling for 64bit… modify your Makefile “gcc -m64 -fPIC -Wall ….” and “sudo make” – Cristian Porta 10 4月. 13

can you please elaborate more ..i went through this over some sites but cannot figure out how should i proceed.. – Ankit Kapoor 10 4月. 13

About recompiling the mysqludf_sys for 64bit you can look at the answer on your post http://dba.stackexchange.com/questions/39752/how-to-resolve-elfclass32-error-in-mysql-for-udf-lib-mysqludf-sys-so – Cristian Porta 07 10月. 13

Ok, try this: “gcc -m64 -fPIC -Wall -I/path/to/your/mysql/basedir -I. -shared lib_mysqludf_sys.c -o /path/to/save/your/new/lib_mysqludf_sys.so” – Cristian Porta 07 10月. 13

i will reply in a day or two… – Ankit Kapoor 08 10月. 13

@user21546 any news? :) – Cristian Porta 11 11月. 13

not yet !! im out for some days..i need to review it again on this project !! – Ankit Kapoor 11 11月. 13

hi ..m here now..can you please help me here…i dnt know how to install lib_mysqludf_sys…once it done…i will go further – Ankit Kapoor 06 12月. 13

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/9211.html

赞 (0)
上一篇 2023-02-13
下一篇 2023-02-13

相关推荐

  • redis查询速度慢_redis读取速度

    redis查询速度慢_redis读取速度当Redis客户端出现请求超时的时候,需要检查该时间点是否有慢查询,从而分析出由于慢查询导致的命令级联阻塞。

    2023-02-19
    157
  • 用Python计算自然常数e的方法

    用Python计算自然常数e的方法自然常数e是数学中一个非常重要的常数,它是一个无理数,约等于2.71828。许多科学领域,比如物理学、化学、统计学等都需要用到自然常数e。计算自然常数,使用Python是非常方便的。

    2023-12-17
    121
  • 使用Python同时遍历两个列表,生成标题

    使用Python同时遍历两个列表,生成标题Python作为一种高级编程语言,有着广泛的应用场景。Python中提供了很多高效的方法来处理列表,而同时遍历两个列表,则是这些方法中常用的一种。在本文中,我们将介绍如何使用Python同时遍历两个列表,并生成对应的标题。

    2024-08-21
    28
  • Python Win32api 安装指南

    Python Win32api 安装指南Win32api是Python编程中非常重要的一个库,它为Python程序提供了非常强大和灵活的Windows API接口。Python Win32api主要用于Windows编程,可以通过WIN32 API调用操作系统的资源。本文将详细介绍Python Win32api的安装步骤。

    2024-06-23
    44
  • sql求合计值(rollup函数应用)[通俗易懂]

    sql求合计值(rollup函数应用)[通俗易懂]CREATE TABLE `test1` ( `id` varchar(11) DEFAULT NULL, `name` varchar(255) DEFAULT NULL, `count` var…

    2023-03-25
    153
  • 以sys.stdout.write为中心写原始标题

    以sys.stdout.write为中心写原始标题在Python中,sys.stdout是用来执行输出操作的标准输出流。它代表着程序标准的输出设备,通常被绑定到控制台窗口或者文件。sys.stdout.write()是标准输出流的方法,它可以将字符串写入标准输出,从而在控制台或文件中显示它们。本文将介绍如何使用sys.stdout.write()来写出具有原始标题的Python程序。

    2024-05-22
    63
  • 动手测起来!搭载全自研数据库内核,我们将性能提升了20%「终于解决」

    动手测起来!搭载全自研数据库内核,我们将性能提升了20%「终于解决」近日,腾讯云MySQL发布新架构,在基础硬件能力、自研内核及外部网络延迟等方面进行了全面升级。 在探究新版本实际性能的过程中,测试人员通过基准测试工具SysBench以及全仿真业务生产环境,分别针对只

    2023-06-05
    146
  • 用了一段时间python了的简单介绍

    用了一段时间python了的简单介绍用到threading的Timer,也类似单片机那样子,在中断程序中再重置定时器,设置中断,python实例代码如下:

    2023-11-02
    153

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注