Changes

Jump to: navigation, search

Teams Winter 2011/team1/BlackBerry/Use SQLite

1,368 bytes added, 22:17, 11 April 2011
11.5 Copy Database File into SDCard
===11.5 Copy Database File into SDCard===
Now that application knows SDCard is present, It should check if the database file exist, otherwise copy it from the application bundle into SDCard:
<source lang="java">
else
{
String dbLocation = "/SDCard/databases/StudentsList/";
// Create URI
uri = URI.create(dbLocation + DB_NAME);
// Open or create a plain text database. This will create the
// directory and file defined by the URI (if they do not already exist).
db = DatabaseFactory.openOrCreate(uri, new DatabaseSecurityOptions(false));
// Close the database in case it is blank and we need to write to the file
db.close();
// Open a connection to the database file
FileConnection fileConnection = (FileConnection)Connector.open("file://" + dbLocation + DB_NAME);
// If the file is blank, copy the pre-defined database from this
// module to the SDCard.
if(fileConnection.exists() && fileConnection.fileSize() == 0)
{
readAndWriteDatabaseFile(fileConnection);
}
// here goes the rest of the constructor code
_studentList = new StudentList(db, uri);
</source>
===11.6 Create SQLiteManager Class===
1
edit

Navigation menu