Java starts when MySQL starts

I am trying to create some MySQL code that will call a Java program from a trigger.

Here is what I still have:

CREATE TRIGGER trig_name after insert ON studentinfo FOR EACH ROW BEGIN END 

The contents of the trigger will then invoke the Java program. Is it possible?

+4
source share
4 answers

The direct answer: no, you cannot call the java method from the mysql trigger. If you had an oracle database, you could, but not mysql.

To do what you want to do with mysql you can

  • make code that updates the database, also notify the swing application. Or you can
  • make the trigger accumulate data in pending operations in a separate table that you periodically read from the swing application.
+5
source

Although this is not a standard feature, it is very good with MySQL. You can use the SELECT .. INTO OUTFILE statement from a trigger to write to a named pipe (Windows) or memroy file system (Linux). Both of these can be easily tracked using Java code (or any other code, for that matter). Using this method, you will avoid polling either because no actual disk access will occur, or you will have good performance.

I wrote a Java package for this, so I'm 100% sure that this is possible and works well. Unfortunately, I am not allowed to share my efforts here (my previous answer was deleted by the moderator), so you will have to encode it yourself, sorry.

+8
source

Calling the java method from an SQL database is not a standard function. An Informix database can call a shell script from a stored procedure, but I do not know about this function in MySQL (I am not a mysql expert).

The closest thing that works with all databases will have a thread and periodic polling of the database for new records.

 SELECT * FROM studentinfo WHERE id > last_seen_id 

Or you can use a timestamp:

 SELECT * FROM studentinfo WHERE create_date >= last_seen_create_date 

In this case, you will have to filter duplicate lines that are already loaded from the previous run.

+1
source

I have to disagree with Joni, look this:
MySQLUDFJavaLauncher
Instructions

+1
source

Source: https://habr.com/ru/post/1393480/


All Articles