Calling the main method

You typically start Java applications (outside the database) by running the Java VM on a class that has a main method.

For example, the Invoice class in the file samples-dir\SQLAnywhere\JavaInvoice\Invoice.java has a main method. When you execute the class from the command line using a command such as the following, it is the main method that executes:

java Invoice
To call the main method of a class from SQL
  1. Declare the method with an array of strings as an argument:

    public static void main( java.lang.String args[] )
    {
    ...
    }
  2. Create a stored procedure that wraps this method.

    CREATE PROCEDURE JavaMain( in arg char(50) )
    EXTERNAL NAME 'JavaClass.main([Ljava/lang/String;)V'
    LANGUAGE JAVA;

    For more information, see CREATE PROCEDURE statement (web services).

  3. Invoke the main method using the CALL statement.

    call JavaMain( 'Hello world' );

    Due to the limitations of the SQL language, only a single string can be passed.