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
Regular Contributor
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

database additions not updating

Hi all,

 

I have written an app that has a sqlite database on the phone, and when the app loads, the app checks a remote server to see if there is any new data to be added to the database. If there is, the data is downloaded and parsed with the JSON parser and added to the database. All of this is working fine. After running the app on the simulator, the data is entered in the database correctly. Here is the problem: when the app runs, the new information is not showing up in the application, even though it is in the database. Is there something I need to do to the database to update the info?

 

Here is the code:

// Open the database            
                db = DatabaseFactory.open(uri);//, databaseOptions);
                System.out.println("database opened again");
                //use sqlmanager to update and delete items from the database
                sqlmanager = new SQLManager(db);
                System.out.println("sqlmanager initialized");
                //Vector dates = sqlmanager.getDates();
                
                //the code below is used the get data from the remote database
                String handlerDateUpdated = "Jun 20 2011 11:30:30AM";//(String)sqlmanager.getDates().elementAt(0);
                String handlerDateDeleted = "Jun 20 2011 11:30:30AM";//(String)sqlmanager.getDates().elementAt(1);
                String url = "http://208.112.30.132/CreativeCoreNew.ashx?dateUpdated=" + handlerDateUpdated + "&dateDeleted=" + handlerDateDeleted;
                url = url.replace(' ', '+');
                System.out.println(url + "***********************************************");
                System.out.println("entering getXml");
                String jsonString = getXml(url);
       //         System.out.println(jsonString);
                
                System.out.println("into fromJSON");
                fromJSON(jsonString, sqlmanager);
                
            // Push a screen onto the UI stack for rendering.

    			UiApplication.getUiApplication().pushScreen(new DirectoryScreen(sqlmanager));
                }catch(DatabasePathException exception){
                	
                }

 and getXML:

       public String getXml(String url){
    	System.out.println("getXml entered");
   		String xml = new String();
   		try {
   			StreamConnection s = null;
               s = (StreamConnection)Connector.open(url);
               System.out.println("StreamConnection opened");
               HttpConnection httpConn = (HttpConnection)s; 
   			
   			int status = httpConn.getResponseCode();
   			if (status == HttpConnection.HTTP_OK){
                   InputStream input = s.openInputStream();
                   System.out.println("inputstream opened");
                   byte[] data = new byte[256];
                   int len = 0;
                   int size = 0;
                   StringBuffer raw = new StringBuffer();
                   System.out.println("getting data");
                   while ( -1 != (len = input.read(data)) ){
                   	raw.append(new String(data, 0, len));
                       size += len;    
                   }
                   xml = raw.toString();
                   System.out.println(xml);
                   input.close();
   			}
   		} catch (IOException e) {
   			//Control de la excepcion de la conexion al servidor
   			e.printStackTrace();
   			System.out.println(e.getMessage());
   		}
   		return xml;
   	}

 

pim
Contributor
Posts: 12
Registered: ‎06-23-2011
My Device: Developer - Bold 9700

Re: database additions not updating

Hi Heather,

 

How are you making sure the new data is in the database?
"the new information is not showing up in the application" - my guess is you're not using the application to check whether the new data exists?

 

If you are, and the data is showing up in, say, the debug console because you print it out there, are you sure the screen is being updated after the data is done being inserted?

 

--

Pim

 

Regular Contributor
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

Re: database additions not updating

I am checking the data in SQLite Browser...

pim
Contributor
Posts: 12
Registered: ‎06-23-2011
My Device: Developer - Bold 9700

Re: database additions not updating

Have you tried printing out in the debug console the new data from the database?

 

If you can see the new data in the debug console, and it's not showing up on the screen, chances are you need to force a repaint of the screen after you update the elements showing the data. Of course I have no idea how you're displaying the data in your application, so I can't help you much there ...

Highlighted
Regular Contributor
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

Re: database additions not updating

I am not displaying the get until all the data has been inserted into the database, so I didn't think I would need to repaint the screen?