Contents Index Lesson 4: Deploy your application to a Windows CE device Tutorial: The CustDB Sample Application

Native UltraLite for Java User's Guide
  Tutorial: An Introductory Application

Lesson 5: Add synchronization to your application


This lesson uses MobiLink synchronization, which is part of SQL Anywhere Studio. You must have the SQL Anywhere Studio installed to carry out this lesson.

The steps involved in this lesson are to add synchronization code to your application, to start the MobiLink synchronization server, and to run your application to synchronize.

The synchronization is carried out with the UltraLite 9.0 Sample database. This is an Adaptive Server Anywhere database that holds several tables. The ULCustomer table has a cust_id column and a cust_name column. During synchronization the data in that table is downloaded to your UltraLite application.

This lesson assumes some familiarity with MobiLink synchronization.

To add synchronization to your application

  1. Add the following method to the Customer.java file:

    private void sync() throws SQLException
    {
      conn.syncParms.setStream( StreamType.TCPIP );
      conn.syncParms.setVersion( "ul_default" );
      conn.syncParms.setUserName( "sample" );
      conn.syncParms.setSendColumnNames( true );
      conn.syncParms.setDownloadOnly( true );
      conn.synchronize();
    }

    This code carries out the following tasks:

  2. Add the following line to the main() method, immediately after the call to the insert method and before the call to the select method:

    cust.sync();
  3. Compile your application, as in Lesson 1: Connect to the database. Do not run the application yet.

To synchronize your data

  1. Start the MobiLink synchronization server.

    From a command prompt, start the MobiLink synchronization server with the following command line:

    dbmlsrv9 -c "dsn=ASA 9.0 Sample" -v+ -zu+ -za

    The ASA 9.0 Sample database has a Customer table that matches the columns in the UltraLite database you have created. You can synchronize your UltraLite application with the ASA 9.0 Sample database.

    The -zu+ and -za command line options provide automatic addition of users and generation of synchronization scripts. For more information on these options, see the MobiLink Synchronization User's Guide.

  2. Run your application, as in Lesson 2: Connect to the database

    The MobiLink synchronization server window displays status messages indicating the synchronization progress. The final message displays Synchronization complete:

    The data downloaded from the sample database are listed at the command prompt window, confirming that the synchronization succeeded:

    Connected to an existing database.
    The table has 128 rows.
    id= 1, name= Gene Poole
    id= 2, name= Penny Stamp
    id= 101, name= Michaels Devlin
    id= 102, name= Beth Reiser
    id= 103, name= Erin Niedringhaus
    id= 104, name= Meghan Mason
    ...

This completes the tutorial.

Samples 

Contents Index Lesson 4: Deploy your application to a Windows CE device Tutorial: The CustDB Sample Application