Exemple de code : ajout d'un schéma à une base de données SQLite
/*
* CreateDatabaseSchema.java
*
* Research In Motion Limited proprietary and confidential
* Copyright Research In Motion Limited, 2010
*/
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.database.*;
import net.rim.device.api.io.*;
public class CreateDatabaseSchema extends UiApplication
{
public static void main(String[] args)
{
CreateDatabaseSchema theApp = new CreateDatabaseSchema();
theApp.enterEventDispatcher();
}
public CreateDatabaseSchema()
{
pushScreen(new CreateDatabaseSchemaScreen());
}
}
class CreateDatabaseSchemaScreen extends MainScreen
{
Database d;
public CreateDatabaseSchemaScreen()
{
LabelField title = new LabelField("SQLite Create " +
"Database Schema Sample",
LabelField.ELLIPSIS |
LabelField.USE_ALL_WIDTH);
setTitle(title);
add(new RichTextField("Adding a table to a database called " +
"MyTestDatabase.db on the SDCard."));
try
{
URI myURI = URI.create("/SDCard/Databases/SQLite_Guide/" +
"MyTestDatabase.db");
d = DatabaseFactory.open(myURI);
Statement st = d.createStatement( "CREATE TABLE 'People' ( " +
"'Name' TEXT, " +
"'Age' INTEGER )" );
st.prepare();
st.execute();
st.close();
d.close();
}
catch ( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
}
}
Sujet parent : Exemples de code
Ces informations vous ont-elles été utiles ? Envoyez-nous vos commentaires.