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
Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN
Accepted Solution

SQLite question

hello and good day ,

please i want to find out if  it is ok to use a thread to handle database connections using sqlite , is it ok ? , if i want to retrieve data from an sqlite database do i wrap it up like i would do a network code to retrieve and display results from an sqlite database , any tips would be appreciated thank you.

Developer
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T

Re: SQLite question

From what I have been doing.

 

  • Open a Database Connection
  • When you need to access the database, call the instance that you opened
  • Create a statement
  • Call/Execute the statement
    • If it is a Select statment, create a Cursor and execute the Statement into the Cursor
    • Close the Cursor
  • Close the Statement

 

repeat when needed

 

When you are down with the application and want to close the application

  • Close the database connection
_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Developer
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T

Re: SQLite question

[ Edited ]

Just a small note.

 

When you use the cursor to get a Select statement.  The values returned start with 0.

 

i.e.  If I wanted the "column1" value, then I get the row item at 0.  "column2" would be at 1 and "column3" would be at 2.

 

 Statement statement = SQLManager.appDB.createStatement("SELECT column1, column2, column3 FROM  " 
    				+ tableName
    				+ "  WHERE Attribute = ?"); 
            statement.prepare();
            statement.bind(1, attribute);
            Cursor cursor = statement.getCursor();              
            Row row;
            cursor.first();
            //Use first cursor spot
            row = cursor.getRow();
            thisValue = row.getString(0);
       
            statement.close();
            cursor.close();

 

I've been banging my head on this all day.  Good thing for break points.

 

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Highlighted
Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: SQLite question

Soo what u mean is that there will be no need to use threads to handle database operations , thanks a lot !, i needed confirmation .