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

SQL Anywhere 12.0.0 (Deutsch) » UltraLiteJ » UltraLiteJ verwenden » UltraLiteJ-Anwendungen entwickeln » Codebeispiele

 

Beispiel: Eine Datenbank synchronisieren

Dieses Beispiel zeigt eine Verbindung zu einem MobiLink-Server zur Synchronisation der Clientdatenbank mit einer konsolidierten Datenbank (in diesem Fall SQL Anywhere).

 ♦  So führen Sie das Sync.java-Beispiel aus
  1. Wechseln Sie zum folgenden Verzeichnis: Beispielverzeichnis\UltraLiteJ.

    Hinweise zum Speicherort von Beispielverzeichnis finden Sie unter Beispielverzeichnis.

  2. Führen Sie das CreateSales-Beispiel aus:

    rundemo CreateSales

    Siehe Beispiel: Eine Verkaufsdatenbank erstellen.

  3. Führen Sie den folgenden Befehl aus, um den MobiLink-Server zu starten:

    start_ml
  4. Führen Sie den folgenden Befehl aus (mit Berücksichtigung der Groß- und Kleinschreibung):

    rundemo Sync
  5. Wenn das Beispiel abgeschlossen ist, fahren Sie den MobiLink-Server herunter. Siehe MobiLink-Server stoppen.



// *****************************************************
// 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 );
	}
    }
}