[All]
Creating a table with JDataStore
By: Ben Matterson
Abstract: Explanation and sample code for creating tables using JDataStore.
Question: How can I create a table in a JDataStore?
To create a table in a JDataStore you can use any component that extends from StorageDataSet including Table/Query/ProcedureDataSet. See the sample below. Note that although this example creates columns for a TableDataSet, StorageDataSets with providers like QueryDataSet and ProcedureDataSets will create columns as needed to retrieve the results from a provide operation. So DataStore is an embedable database that goes a long way in seamlessly supporting the full semantics of the DataExpress data access components.
// === Create a DataStore with a Person table
{
DataStore dataStore = new DataStore();
dataStore.setFileName("/app/mydatastore.jds");
dataStore.create(); // It is now created and open for business.
TableDataSet dataSet = new TableDataSet();
Column name = new Column();
name.setDataType(Variant.STRING);
name.setColumnName("Name");
Column address = new Column();
address.setDataType(Variant.STRING);
address.setColumnName("Address");
dataSet.setColumns(new Column[] {name, address});
dataSet.setStore(dataStore); // If not set, DataSet defaults
// to using MemoryStore
dataSet.setStoreName("/app/Person"); // specify the name of the
// DataSet table in the DataStore.
dataSet.open();
dataStore.close(); // Will automatically close any DataSet using this
// DataStore.
}
// ======================== Open an existing DataStore with a Person table
{
DataStore dataStore = new DataStore();
dataStore.setFileName("/app/mydatastore.jds");
dataStore.open(); // Only works if DataStore already exists.
TableDataSet dataSet = new TableDataSet();
dataSet.setStore(dataStore);
dataSet.setStoreName("/app/Person"); // specify the name of the
// DataSet table in the DataStore.
dataSet.open();
}
Connect with Us