Executing Java methods from database

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I want to store particular algorithms written in Java into a database
(preferably MySQL) and then be able to accept values such as algorithm
type and parameters from a user (via JDBC) which will select the
algorithm from the database, excecute it and return the result.  I
understand that MySQL does not support Java object types, so does
anybody have any suggestions on how I could implement this?  Will I
need to compile the code and then store this into my database?

Thanks a lot


Re: Executing Java methods from database

Quoted text here. Click to load it

You're talking about serializing a Java class, as opposed to an object.  As
far as I know, Java doesn't support serializing classes.  You can serialize
an object, that is an instance of a class.  Then you can deserialize the
object and instantiate it -- if its class is on your classpath.  But Java
doesn't support serializing/deserializing the class itself.

You could convert the compiled Java bytecode for the class into a byte[]
array and store that, but then once you retrieve it, you'd have to write a
custom classloader to get that class into your JVM.  See Jiapi
(http://jiapi.sourceforge.net /) or ObjectWeb ASM (http://asm.objectweb.org /)
which might do what you need.

Alternately, one could use BeanShell (http://www.beanshell.org /) instead of
pure Java to implement the algorithms.  One could store the BeanShell script
in the database as text, retrieve it with JDBC, and execute it using the
eval() method of class bsh.Interpreter
(http://www.beanshell.org/javadoc/bsh/Interpreter.html ).

Bill K.

Site Timeline