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

SQL Anywhere 12.0.0 » UltraLiteJ » Using UltraLiteJ » Developing UltraLiteJ applications » Coding examples


Example: Modifying table definitions

This example demonstrates how to change table definitions. In this scenario, an Invoice table is modified to expand a column length from 50 characters to 100 characters.

 To run the example
  1. Change to the following directory: samples-dir\UltraLiteJ.

    For information about the default location of samples-dir, see Samples directory.

  2. Run the CreateSales example:

    rundemo CreateSales

    See Example: Creating a sales database.

  3. Run the following command (the command is case sensitive):

    rundemo Reorg

// *****************************************************
// 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.*;

/** Reorganize the Invoice table to have a name with an increased size
 * <p>This shows a possible strategy which can be used to reorganize
 * tables, since UltraLiteJ has no table-altering API.
 * <p>The (contrived) example expands the name column to 100 characters.
public class Reorg
     * mainline for program.
     * @param args command-line arguments
    public static void main
	( String[] args )
	try {
	    Configuration config = DatabaseManager.createConfigurationFile( "Sales.ulj" );
	    Connection conn = DatabaseManager.connect( config );
	    PreparedStatement ps = conn.prepareStatement(
	    	"ALTER TABLE Invoice ALTER name VARCHAR(100)" // was VARCHAR(50)
	} catch( ULjException exc ) {
	    Demo.displayException( exc );