Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Call Java Code from MySQL?

I found an article from 2008 discussing how to call Java code from MySQL. There were a lot of caveats and disclaimers because the process involved working with an experimental branch of MySQL.

For a project I have in mind, it would be very useful to be be able to access Java libraries within MySQL, analogous to Oracle's Java Stored Procedures. Does this capability now exist as a standard feature of MySQL? If not, what open source RDBMSs support something similar to Oracle's Java Stored Procedures?

like image 757
Rich Apodaca Avatar asked Jan 09 '10 19:01

Rich Apodaca


3 Answers

PostgreSQL supports pluggable procedure languages, and a project exists to extend PostgreSQL with PL/Java as the language.

I don't recommend putting too much code in the RDBMS. Tools to develop, test, and debug code in the application layer are better than tools for code in the RDBMS.

Also many developers don't understand that code inside the RDBMS should obey transaction isolation. They try to send emails from triggers and so forth. I think code with side effects should be in the application layer, so you don't create phantom effects (e.g. an email may notify of a database change, even though the change was rolled back).

like image 131
Bill Karwin Avatar answered Sep 23 '22 02:09

Bill Karwin


If you can use HSQLDB then you can call java methods directly from SQL: http://hsqldb.org/doc/2.0/guide/sqlroutines-chapt.html#N1240C

like image 24
Denis Tulskiy Avatar answered Sep 24 '22 02:09

Denis Tulskiy


I fully agree with Bill, but I can imagine business rules being stored (not processed) in the database. I'm thinking of drools here. The engine would be in the application, but the rules could be in the database with a management front-end.

Such a beast would be interesting for scenarios where not only the parameters change, but also the formulas can change.

like image 24
extraneon Avatar answered Sep 23 '22 02:09

extraneon