Code sample: Creating an encrypted SQLite database
By default, database files are stored on a media card. If you are using a BlackBerry Smartphone Simulator, you might need to Simulate a media card.
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 CreateEncryptedDatabase extends UiApplication
{
public static void main(String[] args)
{
CreateEncryptedDatabase theApp = new CreateEncryptedDatabase();
theApp.enterEventDispatcher();
}
public CreateEncryptedDatabase()
{
pushScreen(new CreateEncryptedDatabaseScreen());
}
}
class CreateEncryptedDatabaseScreen extends MainScreen
{
Database d;
public CreateEncryptedDatabaseScreen()
{
LabelField title = new LabelField("SQLite Create Encrypted Database Sample",
LabelField.ELLIPSIS |
LabelField.USE_ALL_WIDTH);
setTitle(title);
add(new RichTextField("Creating an encrypted database called " +
"MyEncryptedDatabase.db on the microSD card."));
try
{
URI myURI = URI.create("file:///SDCard/Databases/SQLite_Guide/" +
"MyEncryptedDatabase.db");
DatabaseSecurityOptions dbso = new DatabaseSecurityOptions(true);
d = DatabaseFactory.create(myURI,dbso);
d.close();
}
catch ( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
}
}
Next topic: Performance of
SQLite databases
Previous topic: Security of
SQLite databases