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
New Contributor
Posts: 3
Registered: ‎02-26-2010
My Device: Storm 2
My Carrier: AT & T

SD card in SQLite

hi

 

i m beeginner in blackberry development. I m running the code for SQLite to create the database and insert and reteive the data from the database. There is some code to create database in SDcard with URI . I m not getting what changes i have to make in this code to run it. The code is like

 

URI myURI = URI.create(

 

"/SDCard/Databases/SQLite_Guide/" + "mydatabase.db")

And Please Explain the URI class in simle language......

Thanks...!!!

 

Developer
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: SD card in SQLite

Hi,

 

It sems like you have a lot of reading to do. Tell us what you trying to achieve or what exactly you are trying to do. We'll try and help you.

New Contributor
Posts: 3
Registered: ‎02-26-2010
My Device: Storm 2
My Carrier: AT & T

Re: SD card in SQLite

Hi

 

 Actually i m not getting how to use SQLite database. How to create database and store and retrieve data from it. Can u help me?? I tried the code in one of the doc of blackberry but it didnt work.

And please suggest me some useful  link of the tutorial or some ebook on SQLite.

 

Thanks..!!

New Contributor
Posts: 3
Registered: ‎02-26-2010
My Device: Storm 2
My Carrier: AT & T

Re: SD card in SQLite

Hi

 

The code i have made is lik this

 

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 CreateDb extends UiApplication
{
    
    public static void main(String[] args)
    {
        CreateDb theApp = new CreateDb();
        theApp.enterEventDispatcher();
    }
    public CreateDb()
    {
        pushScreen(new CreateDatabaseScreen());
    }
}
class CreateDatabaseScreen extends MainScreen
{    
    Database d;
    ButtonField b1;
    public CreateDatabaseScreen()
    {        LabelField title = new LabelField("SQLite Create Database Sample",LabelField.ELLIPSIS |LabelField.USE_ALL_WIDTH);
        setTitle(title);
        add(new RichTextField("Creating a database called " + "MyTestDatabase.db on the SDCard."));

        try
        {
            //URI myURI = URI.create("file:///SDCard/databases/CreateDatabase" + "mydatabase.db");
            
            URI myURI = URI.create("file:///SDCard/BlackBerry/documents/");
            d = DatabaseFactory.open(myURI);
            Statement st = d.createStatement( "CREATE TABLE 'People' ( " +
            "'Name' TEXT, " +
            "'Age' INTEGER )" );
            st.prepare();
            st.execute();
            
        }
        catch ( Exception e )
        {
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }
        b1= new ButtonField("Button");
        b1.setChangeListener(listener);
        add(b1);
    }
    FieldChangeListener listener = new FieldChangeListener()
    {
            public void fieldChanged(Field field, int context)
            {
            // TODO Auto-generated method stub
                Dialog.alert("Database created");
            }

            
    };
}

 

 

 

Please tell me the path i have to give in URI and whrere the actual database(like mydatabase.db) i hav to create.

Contributor
Posts: 17
Registered: ‎06-17-2010
My Device: C
My Carrier: SE

Re: SD card in SQLite

Is that problem is solved. Am also using the same and getting this exception:

net.rim.device.api.database.DatabasePathException: Invalid path name. Path does not contains a proper root list. See FileSystemRegistry class for details.Am using eclipse plugin to test the application.

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: SD card in SQLite

When I see that exception it is because my Simulator does not have a simulated SDCard. 

 

When 'adding' a simulated SD Card, I would recommend that you use the 'directory' approach.  So click on the Simulator menu item, Look for SD Card, and add a directory in your computer as the SD Card,  Then you can look at the SD Card directly from your computer. 

Contributor
Posts: 17
Registered: ‎06-17-2010
My Device: C
My Carrier: SE

Re: SD card in SQLite

I have simulated the SDCard from simulator and given the following path in URI:

uri

 

 

= URI.create("file:///SDCard/BlackBerry/Databases" +"moofwd.db"); 

or

uri

= URI.create("/SDCard/BlackBerry/Databases" +"moofwd.db");

In both the cases am getting this exception:

IOInvalid path name. Path does not contains a proper root list. See FileSystemRegistry class for details.

Thanks

 

 

New Contributor
Posts: 3
Registered: ‎06-23-2010
My Device: 8520
My Carrier: TMO

Re: SD card in SQLite

Did you also set a path on your PC/MAC to simulate an SDCard. If not try creating a new folder in your My Documents folder called SDCard and in the simulator settings browse to capture that path.

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: SD card in SQLite

Try the Sample SQLite demo.  Then have a look at how it creates and then opens its database.  Useful code for you I think. 

Developer
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: SD card in SQLite

[ Edited ]

Hi Jasbeern,

Consider this path

 

= URI.create("file:///SDCard/BlackBerry/Databases" +"moofwd.db");

 

Now, if you look real close, after the string concatenation takes place, your path becomes

 

= URI.create("file:///SDCard/BlackBerry/Databasesmoofwd.db");

 

which isn't, im sure, what the real path is. Try this:

 

= URI.create("file:///SDCard/BlackBerry/Databases/" +"moofwd.db");

 

Should work in my humble opinion.

 

PS. Make sure you take a look at the SQLite Demo as Peter said earlier. In case you are wondering what that is here's the link to it (although I believe its there in samples of JDE IDE):

 

http://www.blackberry.com/go/sqlitedemo

 

Also take a look at the SQLite guide for BlackBerry:

 

http://docs.blackberry.com/en/developers/deliverables/8673/JDE_5.0_SQLiteGuide.pdf

 

The code samples provided are awesome.