Contents Index Tutorial: A Java in the database exercise Install the sample Java class

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

Create and compile the sample Java class


The first step is to write the Java code and compile it. This is done outside the database

To create and compile the class

  1. Create a file called Invoice.java holding the following code.

    public class Invoice {
    
      // Fields
      public String lineItem1Description;
      public double lineItem1Cost;
    
      public String lineItem2Description;
      public double lineItem2Cost;
    
      // An instance method
      public double totalSum() {
        double runningsum;
        double taxfactor = 1 + Invoice.rateOfTaxation();
    
        runningsum = lineItem1Cost + lineItem2Cost;
        runningsum = runningsum * taxfactor;
    
        return runningsum;
      }
    
      // A class method
      public static double rateOfTaxation() {
        double rate;
        rate = .15;
    
        return rate;
      }
    }

    You can find source code for this class as the file Samples\ASA\JavaInvoice\Invoice.java under your SQL Anywhere directory.

  2. Compile the file to create the file Invoice.class.

    From a command prompt in the same directory as Invoice.java, execute the following command.

    javac *.java

    The class is now compiled and ready to be installed into the database.


Contents Index Tutorial: A Java in the database exercise Install the sample Java class