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

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - Programming » Java in the database » Tutorial: Using Java in the database

 

Lesson 2: Selecting a Java VM

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

Prérequis

Complete the steps in Lesson 1 before attempting Lesson 2.

This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Using Java in the database.

Contexte et remarques

If you do not have a Java Runtime Environment (JRE) installed, you can install and use any Java JRE as long as it is version 1.6 or later. Most Java installers set up one of the JAVA_HOME or JAVAHOME environment variables. If neither of these environment variables exist, you can create one manually, and point it to the root directory of your Java VM. However, this configuration is not required if you use the ALTER EXTERNAL ENVIRONMENT statement.

 Task
  1. Use Interactive SQL to start the personal database server and connect to the sample database.

    dbisql -c "DSN=SQL Anywhere 16 Demo"
  2. This step is optional. Execute a statement like the following.

    ALTER EXTERNAL ENVIRONMENT JAVA
    LOCATION 'c:\\jdk1.7.0\\jre\\bin\\java.exe';

    If the location of the Java VM is not specified using the LOCATION clause of the ALTER EXTERNAL ENVIRONMENT JAVA statement or the location specified is incorrect, 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 system PATH.

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

  3. This step is optional. Use the java_vm_options database option to specify any additional command-line options that are required to start the Java VM.

    SET OPTION PUBLIC.java_vm_options='java-options';
  4. Use the START JAVA statement to start the Java VM.

    START JAVA;

    This statement attempts to preload the Java VM. If the database server is not able to locate and start the Java VM, then an error message is issued. This statement is optional since the database server automatically loads the Java VM when it is required.

Résultat

The LOCATION clause of the ALTER EXTERNAL ENVIRONMENT JAVA statement indicates the location of the Java VM. The START JAVA statement loads the Java VM.

Suivant

In the next lesson, you install the Java class into the database. Proceed to Lesson 3: Installing a Java class.

 See also