本示例演示与 MobiLink 服务器连接,以便同步客户端数据库和统一(在本例中是 SQL Anywhere)数据库。
转到以下目录:samples-dir\UltraLiteJ。
有关 samples-dir 缺省位置的信息,请参见示例目录。
运行 CreateSales 示例:
rundemo CreateSales |
请参见示例:创建销售数据库。
运行以下命令启动 MobiLink 服务器:
start_ml |
运行以下命令(此命令区分大小写):
rundemo Sync |
完成示例后,关闭 MobiLink 服务器。请参见停止 MobiLink 服务器。
// ***************************************************** // 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 ); } } } |
![]() |
使用DocCommentXchange 讨论此页。
|
版权 © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |