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 |
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.
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() |
Run the application again in the simulator.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |