iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > JAVA >Execution of a Java program by a trigger.
  • 533
分享到

Execution of a Java program by a trigger.

ExecutionofaJavaprogrambyatrigger. 2019-01-26 15:01:59 533人浏览 绘本
摘要

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

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;
|

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

no solution has been provided on this http://dba.stackexchange.com/questions/39752/how-to-resolve-elfclass32-error-in-mysql-for-udf-lib-mysqludf-sys-so  Ankit Kapoor 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

--结束END--

本文标题: Execution of a Java program by a trigger.

本文链接: https://www.lsjlt.com/news/5288.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作