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

Web and WebWorks Development

Reply
New Contributor
Posts: 9
Registered: ‎10-19-2010
My Device: 9700

Read Gears Database in Java application

Hi,

 

Is there any way to read the database created by Widget app using Google Gears in native Java application.

 

I am using Javascript extensions in my widget application, and want to update the database through the JavaScript extension which I have.

 

When I am trying to open the database on actual device (9700 BOLD), I am getting "net.rim.device.api.database.DatabaseIOException".

 

Is this something to do with the fact that database created by Gear are by default encrypted.

 

I am using below Java code to open the database -

 

 

Database d = null;
String appName = "MyDB";
String appNameBase64 = null;
URI myURI= null;
try {
appNameBase64 = new String(Base64OutputStream.encode(appName.getBytes(), 0, appName.length(), false, false));
myURI = URI.create("file:///SDCard/BlackBerry/system/appdata/rim/gears/"+appNameBase64+"/local--0/db_User.db");
d = DatabaseFactory.open(myURI);
} catch (Exception e) {
fileWrite("Cannot Open database :: " + e.toString()+" Message:: "+e.getMessage()+" URI :: "+myURI,
"file:///SDCard/dbError1.txt");
try {
myURI = URI
.create("file:///store/home/user/appdata/rim/gears/"+appNameBase64+"/local--0/db_User.db");
d = DatabaseFactory.open(myURI);
} catch (Exception ex) {
fileWrite("Cannot Open database :: " + ex.toString(),
"file:///SDCard/dbError.txt");
}
}

 

 

In first attempt I am trying to open the database from SDCard, if that fails I am hitting the device memory for database.

 

 

Please let me know I am doing anything wrong here, or there is specific way to handle the database created by Google Gear in Java.

 

Any inputs on this issue are most welcome.

 

Simulator OS version : 5.0.0.586

 

Thanks in Advance!!!

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Read Gears Database in Java application

Hi ziya_sayed,

 

It is not possible to open a Gears DB in a Java application. The database is encrypted and can only be accessed by the website or WebWorks/Widget application that created it.

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 9
Registered: ‎10-19-2010
My Device: 9700

Re: Read Gears Database in Java application

Hi Tim,

 

Thanks for your quick reply on this.

 

But, it is quite interesting that, this code runs perfectly on simulator, i didnt get any exceptions as such.

 

Any workaround on this, because I dont see any option other than updating the database in Java, since I am synching some data to the server in separate thread and want to update the database as per the response from server.

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Read Gears Database in Java application

I'm curious on why you cannot sync the database from within your widget/WebWorks application?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 9
Registered: ‎10-19-2010
My Device: 9700

Re: Read Gears Database in Java application

Let me explain you the background on this.

 

I am developing an offline tool for e-learning, in which I have a set of server API's which are authenticated, for each request I have to set the "Authorization" header in the HTTPRequest.

 

Earlier we were using the XMLHttpRequest object for server communication, this was working great on all of the simulators, but when we actually ported the application on BB device (9700 BOLD), we ran into authentication issues.

 

Then we came to know that BASIC authentication is not yet supported by BB Widgets. (Reference : https://www.blackberry.com/jira/browse/WEBAPI-21)

 

This was the reason why we had to convert all the server communication in JavaScript extension.

 

Now, everything is set in Javascript extension, with this only issue.

 

For Sync, I am running a separate thread, and for this reason I am not able to return the server status code to my main Widget App where I am supposed to update the database as per the response code..

 

So, somehow I want to update the database from Java itself.

 

Thanks!

Ziya.

Highlighted
New Contributor
Posts: 9
Registered: ‎10-19-2010
My Device: 9700

Re: Read Gears Database in Java application

Hey I got the solution for my problem... Smiley Happy

 

There is no need to read/write the SQLite database in JAVA.

 

Simply we can pass a callback function to the JS Extension which will handle the database stuff back in widget itself.

 

More on CallBack functions in JS extensions in below links - 

 

http://supportforums.blackberry.com/t5/Web-Development/Widget-Javascript-Extension-Callback/m-p/4724...

 

 

http://supportforums.blackberry.com/t5/Web-Development/Initialize-BrowserField-object-in-JS-Extensio...