Executing Java methods from database
am 02.03.2006 16:39:18 von Paul
Hi,
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
Paul
Re: Executing Java methods from database
am 02.03.2006 20:03:13 von Bill Karwin
"Paul" wrote in message
news:1141313957.952582.13200@e56g2000cwe.googlegroups.com...
> 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?
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).
Regards,
Bill K.