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

SQL Anywhere 11.0.1 » UltraLiteJ » Using UltraLiteJ » Tutorial: Build a BlackBerry application » Part 2: Adding synchronization to the BlackBerry application


Lesson 3: Add synchronization to the application

In this lesson, you add synchronization capabilities to your application.

  1. In the HomeScreen constructor, add a Sync menu item.

    // Add a menu item
    // Add sync menu item
    // Create database and connect
    try{ ...
  2. Define the menu item in the class variables declarations.

    private MenuItem _addToListMenuItem = new MenuItem("Add", 1, 1){
            public void run() {
    private MenuItem _syncMenuItem = new MenuItem("Sync", 2, 1){
            public void run() {
  3. Create the onSync method.

    private void onSync(){
            if( _da.sync() ){
                _statusLabel.setText("Synchronization succeeded");
            } else {
                _statusLabel.setText("Synchronization failed");
        } catch ( Exception ex){
            System.out.println( ex.toString() );
  4. Define the syncParms and streamParms variables at the class level.

    private static SyncParms _syncParms;
    private static StreamHTTPParms _streamParms;
  5. In the DataAccess class, add a sync method.

    public boolean sync() {
        try {
            if( _syncParms == null ){
                String host = "";
                _syncParms = _conn.createSyncParms( "mluser", "HelloBlackBerrySyncModel" );
                _streamParms = _syncParms.getStreamParms();
                _streamParms.setPort( 80 ); // use your own
                _streamParms.setHost( host ); // use your own
            System.out.println( "Synchronizing" );
            _conn.synchronize( _syncParms ); 
            return true;
        catch( ULjException uex){
            return false;

    The synchronization parameters object, SyncParms, includes the user name and password that you specified when deploying the synchronization model. It also includes the name of the synchronization model you created. In MobiLink, this name now refers to the synchronization version, or a set of synchronization logic, that was deployed to your consolidated database.

    The stream parameters object, StreamHTTPParms, indicate the host name and port number of the MobiLink server. When you start the MobiLink server in the next lesson, use your own computer name and select a port that is available. Do not use localhost as your computer name. You can use port 80 if you have no web server running on your computer.

  6. Compile your application.