2013-05-17 66 views
1

嗨,我是黑莓发展的新手。如何在Blackberry模拟器中使用sqlite数据库?

我想创建一个小型的演示应用程序的sqlite。对于我写了下面的代码:

try 
    { 
     URI myURI = URI.create("file:///SDCard/Databases/myDb.db"); 
     d = DatabaseFactory.openOrCreate(myURI); 
     d.close(); 
     add(new RichTextField("DB created successfully")); 
    } 
    catch (Exception e) 
    {   
     System.out.println(e.getMessage()); 
     e.printStackTrace(); 
     add(new RichTextField("Error: "+e.toString())); 
    } 

当我运行此我得到一个例外,这样

net.rim.device.api.database.DatabasePathException:无效的路径名。路径不包含正确的根目录。有关详细信息,请参阅FileSystemRegistry类。

我已经设置SD卡在模拟器:模拟 - >更改SD卡 - >添加目录(E:\ mediacard)

回答

3

后设立的SD卡,找到从文件浏览器和SD卡模拟器检查它是否正确安装。

要了解使用SQLite数据库时的最佳做法,请检查http://docs.blackberry.com中提供的SQLite示例应用程序。如果您使用BlackBerry Plugins For Eclipse,那么您可以导入SQLiteDemo应用程序并检查代码。以下几行代码来自SQLiteDemo类的构造函数。

// 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) { 
    // no database can't be created 
}   
else { 
    // create database 
} 
+0

非常感谢你我解决了这个问题 – user2199280

相关问题