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

SQL Anywhere 10.0.1 » MobiLink - Getting Started » Tutorial: Using Java Synchronization Logic

Introduction to Java Synchronization tutorial Next Page

Lesson 1: Compile the CustdbScripts Java class

Java classes encapsulate synchronization logic in methods.

In this lesson, you will compile a class associated with the CustDB sample database.

MobiLink Database Sample

SQL Anywhere ships with a SQL Anywhere sample database (CustDB) that is already set up for synchronization, including the SQL scripts required for synchronization. The CustDB ULCustomer table, for example, is a synchronized table that supports a variety of table-level events.

CustDB is designed to be a consolidated database server for both UltraLite and SQL Anywhere clients. The CustDB database has a DSN called SQL Anywhere 10 CustDB.

CustdbScripts class

In this section, you create a Java class called CustdbScripts with logic to handle the ULCustomer upload_insert and download_cursor events. You enter the CustdbScripts code in a text editor and save the file as

To create
  1. Create a directory for the Java class and assembly.

    This tutorial assumes the path c:\mljava.

  2. Using a text editor, enter the CustdbScripts code:

    public class CustdbScripts {
        public static String UploadInsert() {
            return("INSERT INTO ULCustomer(cust_id,cust_name) values (?,?)");
        public String DownloadCursor(java.sql.Timestamp ts,String user ) {
               "SELECT cust_id, cust_name 
                FROM ULCustomer where last_modified >= ' " + ts + " ' ");

    The class and associated methods must be set as public.

  3. Save the file as in c:\mljava.

Compiling the Java source code

To execute Java synchronization logic, the MobiLink server must have access to the classes in mlscript.jar. This jar file contains a repository of MobiLink server API classes to use in your Java methods.

When compiling Java source code for MobiLink, you must include mlscript.jar to make use of the MobiLink server API. In this section, you use the javac utility's -classpath option to specify mlscript.jar for the CustdbScripts class.

To compile the Java source code (Windows)
  1. At a command prompt, navigate to the folder containing (c:\mljava).

  2. Type the following command. Replace install-dir with the location of your SQL Anywhere installation.

    javac -classpath "install-dir\java\mlscript.jar"
  3. The CustdbScripts.class file is generated.

    Further reading

    For more information about the MobiLink server API for Java, see MobiLink server API for Java Reference.

    For more information about Java methods, see Methods.

    For more information about the CustDB sample database, and using alternate RDBMS servers, see Setting up the CustDB consolidated database.