Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.0 (Français) » SQL Anywhere Server - Programming » Java in the database » Special features of Java classes in the database


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\ 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'

    For more information, see CREATE PROCEDURE statement (external procedures).

  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.