08-23-2012 03:47 AM
Hi All,
I am using SQLITE in my application but whenever i try to open database file. It gives me the following error.
db = DatabaseFactory.openOrCreate(uri, new DatabaseSecurityOptions(false));
error comes at the above line.
net.rim.device.api.database.DatabaseIOException: Sqlite initialization failed: : out of memory
Please guide me.
Thanks
Ekansh
08-23-2012 06:06 AM
where are you creating database SDCard/Store ??
08-23-2012 06:23 AM
public void openDB(String DB_NAME) {
DBNAME = DB_NAME;
try {
String dbLocation = "/SDCard/databases/";
// Determine if an SDCard is present
boolean sdCardPresent = false;
String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements()) {
root = (String) e.nextElement();
if (root.equalsIgnoreCase("sdcard/")) {
sdCardPresent = true;
}
}
if (!sdCardPresent) {
// If an SDCard is not available we will store our database in
// flash memory. This is not recommended for large databases.
dbLocation = "/store/home/user/";
}
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 it does 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 or flash memory.
if (fileConnection.exists() && fileConnection.fileSize() == 0) {
readAndWriteDatabaseFile(fileConnection);
}
// Open the database
db = DatabaseFactory.open(uri);
} catch (Exception ex) {
System.out.println("Exception id Database Login openDB() :: "
+ ex.toString());
}
}I have posted my code.
Please see.
08-23-2012 06:58 AM
Went through your code it’s seemed fine & compare with the code. Can you plz check your sdcard or phone memory.
following is the sample example code
{
String dbLocation = "/SDCard/databases/SQLite Demo/";
// Create URI
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).
Database 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);
}
// Retrieve the code signing key for the XYZ key file
CodeSigningKey codeSigningKey = CodeSigningKey.get(CodeModuleManager.getModuleHand
try
{
// Encrypt and protect the database. If the database is already
// encrypted, the method will exit gracefully.
DatabaseFactory.encrypt(uri, new DatabaseSecurityOptions(codeSigningKey));
}
catch(DatabaseException dbe)
{
errorDialog("Encryption failed - " + dbe.toString());
}
// Create a new DatabaseOptions object forcing foreign key constraints
DatabaseOptions databaseOptions = new DatabaseOptions();
databaseOptions.set( "foreign_key_constraints", "on" );
// Open the database
db = DatabaseFactory.open(uri, databaseOptions);
// Create a new main screen and push it onto the display stack
SQLiteDemoScreen screen = new SQLiteDemoScreen(new SQLManager(db));
pushScreen(screen);
}
08-23-2012 08:38 AM
08-23-2012 09:23 AM