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

SQL Anywhere 12.0.1 » SQL Anywhere Server - Programming » Java in the database


Java VMs

The database server must be set up to locate a Java VM. Since you can specify different Java VMs for each database, the ALTER EXTERNAL ENVIRONMENT statement can be used to indicate the location (path) of the Java VM.

LOCATION 'c:\\jdk1.6.0_20\\jre\\bin\\java.exe';

If the location is not set, the database server searches for the location of the Java VM, as follows:

  • Check the JAVA_HOME environment variable.

  • Check the JAVAHOME environment variable.

  • Check the path.

  • If the VM cannot be located, return an error.


JAVA_HOME and JAVAHOME are environment variables commonly created when installing a Java VM. If neither of these exist, you can create them manually, and point them to the root directory of your Java VM. However, this is not required if you use the ALTER EXTERNAL ENVIRONMENT statement.

 Specify the location of the Java VM (Interactive SQL)
  1. Start Interactive SQL and connect to the database.

  2. In the SQL Statements pane, type the following statement:

    LOCATION 'path\\java.exe';

    Here, path indicates the location of the Java VM (for example, c:\\jdk1.6.0_20\\jre\\bin).

Use the java_vm_options option to specify any additional command line options that are required to start the Java VM.

SET OPTION PUBLIC.java_vm_options='java-options';

If you want to use JAVA in the database, but do not have a Java Runtime Environment (JRE) installed, you can install and use any Java JRE that you want to. Once installed, it is best to set the JAVA_HOME or JAVAHOME environment variable to point to the root of the installed JRE. Note that most Java installers set one of these environment variables by default. Once a JRE is installed and JAVA_HOME or JAVAHOME is set correctly, you should then be able to use Java in the database without performing any additional steps.

 See also