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

Posts: 17
Registered: ‎06-18-2012
My Device: Bold 9900
My Carrier: Globacom

HTML5 Database not working

I'm tryna create a database and store some data in it. When I test my code on my blackberry 9900, it alerts me that the database was created successfully and that the table I wanna create too was created successfully. The problem is, whenever I want to do an insert or a select, i get an error that the database table does not exist. Please is there a problem with HTML5 database and BB Web Works. Here's a sneak into my code.


function createDB(){
globalVar.db = window.openDatabase("TestDB8","1.0","Notification storage",5*1024*1024, onDBCreate);
alert("This device does not have HTML5 database support");


function onDBCreate(database){
tx.executeSql('CREATE TABLE notification(`id` INTEGER PRIMARY KEY AUTOINCREMENT , `subject` varchar(255), `message` varchar(4000), `time` datetime, `status` tinyint(1) DEFAULT 0)',[],
function(tx, res){
alert("Database Table notification was successfully created");
function(tx, err){
alert("Error creating table: "+err.message);



tx.executeSql('INSERT INTO notification(`subject`,`message`,`time`,`user_id`,`status`) VALUES(?,?,?,?,?)',[subject,message,time,globalVar.userid,0],
alert('Notification was added successfully');
alert('Couldnt add notification: '+err.message);



t.executeSql('SELECT count(*) AS c FROM notification', [], function(t, r){
var len = r.rows[0].c;
alert("Total notifications: "+len);
function(t, e){
alert("Can't read records: "+e.message); 



Please can someone tell me what's wrong. I read through the documentation closely and followed the instructions there.

Posts: 17
Registered: ‎08-23-2012
My Device: developer
My Carrier: n/a

Re: HTML5 Database not working

[ Edited ]

From the api

we see:

void transaction (callback: function(transaction : SQLTransaction), [errorCallback: function(error : SQLError)], [successCallback: function()]) 

Your success and error callbacks are the wrong way round . . . 


BTW: A gotcha that cought me out when testing this that I didnt see in th docs is that the blackberry must be unplugged from usb after deployment for testing (at least on OS 5.0). Access to the SD card is required and there is no access when the the phone is connected via USB.


Edit: I suspect your create table is erroneously reporting success when it is actually failing because the table is already created and the inserts are erroneously reporting a fail when they are actually succeeding . . .