Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 27
Registered: ‎03-24-2011
My Device: Playbook, Developer
My Carrier: --
Accepted Solution

Database in the Resource Folder

I have an SQLite database with names of 100 countries and their lat-lon info.

I want to place this in the resource folder and read/edit its entries. 

Is it possible ? If yes please tell me how ?

 

I know how to create and manage database on SD Card but want to know how to place database within the application.

 

Please help....

Developer
Posts: 466
Registered: ‎03-04-2009
My Device: 8520
My Carrier: some

Re: Database in the Resource Folder

you have two options actually.

Either copy at runtime your db file to SDCard location or copy to internal file system. The last option is useful only for limited number of device. Bottom line is that SQLite can work only from SDCard or from filesystem(in rare cases)

Got resolved! Press kudo icon!
Contributor
Posts: 27
Registered: ‎03-24-2011
My Device: Playbook, Developer
My Carrier: --

Re: Database in the Resource Folder

Thank you for the response. I have 2 issues if you can help me.

 

1) How secure is it to save database on the SD card. Is there any way to protect it from external usage.

 

2) I tried below code to copy database from resource folder to SD card. But i get " Not a File Exception "

 

public void copyFile(String srFile, String dtFile) { try {

    FileConnection fconn;


    fconn = (FileConnection) Connector.open(dtFile,Connector.READ_WRITE);

    if(!fconn.exists()) // if  file does not exists , create a new one
    {
        fconn.create();
    }
    InputStream is = getClass().getResourceAsStream(srFile);
    OutputStream os =fconn.openOutputStream();
    byte[] buf = new byte[1024];
    int len;
    while ((len = is.read(buf)) > 0)
    {
        os.write(buf, 0, len);
    }
   is.close();
   os.close();
}
catch(IOException e)
{

}
Highlighted
Contributor
Posts: 27
Registered: ‎03-24-2011
My Device: Playbook, Developer
My Carrier: --

Re: Database in the Resource Folder

Guys thank you for the support.

I was able to sort out things.

The Sqlite Demo application had all the answers.

Developer
Posts: 466
Registered: ‎03-04-2009
My Device: 8520
My Carrier: some

Re: Database in the Resource Folder

great! SQLite has support for encryption. I presume you're aware of this already.

Got resolved! Press kudo icon!