Contents Index Supported classes Using threads in Java applications

ASA Programming Guide
  Using 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 JDBCExamples class in the file Samples\ASA\Java\JDBCExamples.java under your SQL Anywhere directory 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 JDBCExamples

For more information about how to run the JDBCExamples class, see Establishing JDBC connections.

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. Invoke the main method using the CALL statement.

    Each member of the array of strings must be of CHAR or VARCHAR data type, or a literal string.

Example 

The following class contains a main method which writes out the arguments in reverse order:

public class ReverseWrite {
  public static void main( String[] args ){
    int i:
    for( i = args.length; i > 0 ; i-- ){
        System.out.print( args[ i-1 ] );
    }
  }
}

You can execute this method from SQL as follows:

call ReverseWrite.main( ' one', ' two', 'three' )

The database server window displays the output:

three two one

Contents Index Supported classes Using threads in Java applications