Product Documentation

c-treeDB API for Java

Previous Topic

Next Topic

Define

Define() establishes specific data definitions. This involves defining columns/fields and creating the tables/files with optional indexes.

Below is the code for Define():

//

// Define()

//

// Open the table, if it exists. Otherwise create and open the table

//

static void Define() throws IOException {

boolean do_create = false;

System.out.println("DEFINE");

try {

System.out.println("\tOpen table...");

MyTable.Open("custmast", OPEN_MODE.NORMAL);

} catch (CTException E) {

// table does not exist. Try to create it

do_create = true;

}

if (do_create) {

// create the table

System.out.println("\tAdd fields...");

try {

MyTable.AddField("cm_custnumb", FIELD_TYPE.CHARS, 4);

MyTable.AddField("cm_custzipc", FIELD_TYPE.CHARS, 9);

MyTable.AddField("cm_custstat", FIELD_TYPE.CHARS, 2);

MyTable.AddField("cm_custrtng", FIELD_TYPE.CHARS, 1);

MyTable.AddField("cm_custname", FIELD_TYPE.VARCHAR, 47);

MyTable.AddField("cm_custaddr", FIELD_TYPE.VARCHAR, 47);

MyTable.AddField("cm_custcity", FIELD_TYPE.VARCHAR, 47);

System.out.println("\tCreate table...");

MyTable.Create("custmast", CREATE_MODE.NORMAL);

MyTable.Open("custmast", OPEN_MODE.NORMAL);

} catch (CTException E) {

Handle_Exception(E);

}

} else {

Check_Table_Mode(MyTable);

}

}

TOCIndex