Executing Java methods from database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    #1

    Executing Java methods from database

    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

  • Bill Karwin

    #2
    Re: Executing Java methods from database

    "Paul" <Paul.Jones05@g ooglemail.com> wrote in message
    news:1141313957 .952582.13200@e 56g2000cwe.goog legroups.com...[color=blue]
    > 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?[/color]

    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.


    Comment

    Working...