This example demonstrates connecting to a MobiLink server to synchronize the client database with a consolidated (in this case, SQL Anywhere) database.
To run the Sync.java exampleChange to the following directory: samples-dir\UltraLiteJ.
For information about the default location of samples-dir, see Samples directory.
Run the CreateSales example:
rundemo CreateSales |
Run the following command to start the MobiLink server:
start_ml |
Run the following command (the command is case sensitive):
rundemo Sync |
Once the example completes, shut down the MobiLink server. See Stopping the MobiLink server.
// *****************************************************
// Copyright (c) 2006-2010 iAnywhere Solutions, Inc.
// Portions copyright (c) 2006-2010 Sybase, Inc.
// All rights reserved. All unpublished rights reserved.
// *****************************************************
// This sample code is provided AS IS, without warranty or liability
// of any kind.
//
// You may use, reproduce, modify and distribute this sample code
// without limitation, on the condition that you retain the foregoing
// copyright notice and disclaimer as to the original iAnywhere code.
//
// *********************************************************************
package com.ianywhere.ultralitej.demo;
import com.ianywhere.ultralitej12.*;
/**
* Sync: sample program to demonstrate Database synchronization.
*
* Requires starting the MobiLink Server Sample using start_ml.bat
*/
public class Sync
{
/**
* mainline for program.
*
* @param args command-line arguments
*
*/
public static void main
( String[] args )
{
try {
Configuration config = DatabaseManager.createConfigurationFile( "Demo1.ulj" );
Connection conn = DatabaseManager.createDatabase( config );
PreparedStatement ps = conn.prepareStatement(
"CREATE TABLE ULCustomer" +
"( cust_id int NOT NULL PRIMARY KEY" +
", cust_name VARCHAR(30) NOT NULL" +
")"
);
ps.execute();
ps.close();
//
// Synchronization
//
// Version set for MobiLink 12.0.x
SyncParms syncParms = conn.createSyncParms( SyncParms.HTTP_STREAM, "50", "custdb 12.0" );
syncParms.getStreamParms().setPort( 9393 );
conn.synchronize( syncParms );
SyncResult result = syncParms.getSyncResult();
Demo.display(
"*** Synchronized *** bytes sent=" + result.getSentByteCount()
+ ", bytes received=" + result.getReceivedByteCount()
+ ", rows received=" + result.getReceivedRowCount()
);
conn.release();
} catch( ULjException exc ) {
Demo.displayException( exc );
}
}
}
|
![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |