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

SQL Anywhere 12.0.0 (Français) » UltraLiteJ » Using UltraLiteJ » Tutorial: Building an UltraLiteJ application for BlackBerry » Part 1: Create a new BlackBerry UltraLiteJ application for BlackBerry

 

Lesson 4: Create a database table

In this lesson, you create a simple table called Names, which contains two columns that have the following properties:

Column name Data type Allow null? Default Primary key?
ID UUID No None Yes
Name Varchar(254) No None No
  1. Add a DataAccess method to create the table.



    private void createDatabaseSchema()
    {
        try{
            String sql = "CREATE TABLE Names ( ID UNIQUEIDENTIFIER DEFAULT NEWID(), Name VARCHAR(254), " +
                "PRIMARY KEY ( ID ) )";
            PreparedStatement ps = _conn.prepareStatement(sql);
            ps.execute();
            ps.close();
        }
        catch( ULjException uex1){
            Dialog.alert( "ULjException: " + uex1.toString() );
        }
        catch( Exception ex1){
            Dialog.alert( "Exception: " + ex1.toString() );
        }
    }

    If the table already exists, an exception is thrown.

  2. Call the DataAccess.getDataAccess method.

    Uncomment the call to createDatabaseSchema in the sample code from Part 1, Lesson 3, Step 3. The call to createDatabaseSchema should look like the following:

    _da.createDatabaseSchema()
  3. Run the application again in the simulator.