Contents Index Install the sample Java class Access fields and methods of the Java object

ASA Programming Guide
  Introduction to Java in the Database
    Tutorial: A Java in the database exercise

Creating a SQL variable of type Invoice


This section creates a SQL variable that references a Java object of type Invoice.

Case sensitivity 
Java is case sensitive, so the portions of the following examples in this section pertaining to Java syntax are written using the correct case. SQL syntax is rendered in upper case.
  1. From Interactive SQL, execute the following statement to create a SQL variable named Inv of type Invoice, where Invoice is the Java class you installed to a database:

    CREATE VARIABLE Inv Invoice

    Once you create a variable, it can only be assigned a value if its data type and declared data type are identical or if the value is a subclass of the declared data type. In this case, the variable Inv can only contain a reference to an object of type Invoice or a subclass of Invoice.

    Initially, the variable Inv is NULL because no value has been passed to it.

  2. Execute the following statement to identify the current value of the variable Inv.

    SELECT IFNULL(Inv,
        'No object referenced',
        'Variable not null: contains object reference')

    The variable currently has no object referenced.

  3. Assign a value to Inv.

    You must instatiate an instance of the Invoice class using the NEW keyword.

    SET Inv = NEW Invoice()

    The Inv variable now has a reference to a Java object. To verify this, you can execute the statement from step 2.

    The Inv variable contains a reference to a Java object of type Invoice. Using this reference, you can access any of the object's fields or invoke any of its methods.


Contents Index Install the sample Java class Access fields and methods of the Java object