ASA Programming Guide
Introduction to Java in the Database
Tutorial: A Java in the database exercise
The first step is to write the Java code and compile it. This is done outside the database
To create and compile the class
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.
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.