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 Member
arsahe
Posts: 1
Registered: ‎06-19-2012
My Device: Tourch

Is retrieving data same as using it?

[ Edited ]

Hi Blackberry community,

I'm a new member in your community and i'm new to the blackberry in general. I have a question about the differences between two codes that should slightly work in a  similar way.

 

The first one is to read data from the data base

 try
        {
            URI myURI = URI.create("file:///SDCard/Databases/SQLite_Guide/MyTestDatabase.db");
            d = DatabaseFactory.open(myURI);
           
            Statement st = d.createStatement("SELECT Name,Age FROM People");

            st.prepare();
            Cursor c = st.getCursor();
           
            Row r;
            int i = 0;
            while(c.next())
            {
                r = c.getRow();
                i++;
                add(new RichTextField(i + ". Name = " + r.getString(0) +
                                          " , " +
                                          "Age = " + r.getInteger(1)));
            }
            if (i==0)
            {
                add(new RichTextField("No data in the People table."));
            }
            st.close();
            d.close();

        }
        catch ( Exception e )
        {        
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }         
    }

 

 and the second one is to read data from the database but save them to show them in a auto complete field

 

class ReadDataScreen  extends MainScreen

{

Database d;

 

publicReadDataScreen() {

 

 

BasicFilteredList  filterLst = new BasicFilteredList();

 

filterLst.addDataSet(1,getDataFromDB() ,"Names",BasicFilteredList.COMPARISON_IGNORE_CASE);

AutoCompleteField autoFld =newAutoCompleteField(filterLst);

add(autoFld);

 

}

publicString[] getDataFromDB(){

 

Vector fNames =

newVector();

 

try

{

 

URI myURI = URI.create("file:///SDCard/Databases/SQLite_Guide/MyTestDatabase.db");

 

d = DatabaseFactory.open(myURI);

Statement st =

d.createStatement("SELECT Name FROM People");

 

st.prepare();

st.execute();

 

Cursor c = st.getCursor();

 

Row r;

while(c.next())

{

r = c.getRow();

//fNames is Vector

 

fNames.addElement(r.getString(0));

 

System.out.print(fNames);

}

st.close();

d.close();

 

}

catch( Exception e )

{

System.out.println( e.getMessage() );

e.printStackTrace();

}

 

String [] returnValues =

newString[fNames.size()];

 

for (inti = 0; i < fNames.size(); i++) {

returnValues[i] = (String) fNames.elementAt(i);

}

returnreturnValues;

 

 

 

}

 

 Why in the first code i'm successfully able to read from the database and showing it in the screen, while in the second code it takes me to the exception ([0.0] Invalid path name. Path does not contains a proper root list. See FileSystemRegistry class for detai[0.0] ls.)

 

I would be thankful for any help you can give me.