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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Regular Contributor
Posts: 77
Registered: ‎06-13-2013
My Device: 9900
My Carrier: blackberry cure

How to check table exit or not in db phonegap



i need to check whether the table exit or not in db.actually i need to add data then i need show data on list liew .In starting i need to show all data which is present on db on listview.but when user come first time there is not table it give error undefined.how to check table exit or not ?


here is my code 



$(document).ready(function() {



//document.addEventListener("deviceready", onDeviceReady, false);
function doesTableExist(connectionSmiley FrustratedQLConnection, tableNameSmiley Frustratedtring):Boolean
var schemaSmiley FrustratedQLSchemaResult = connection.getSchemaResult();

for each (var tableSmiley FrustratedQLTableSchema in schema.tables)
if (table.name.toLowerCase() == tableName.toLowerCase())
return true;
return false;
var db = "";
//will create database Dummy_DB or open it

//function will be called when device ready
function onDeviceReady(){
db = window.openDatabase("Casepad", "1.0", "Casepad", 200000);

// db.transaction(populateDB, errorCB, successCB);
function insertData(){
db.transaction(populateDB, errorCB, successCB);

//create table and insert some record
function populateDB(tx) {
tx.executeSql('INSERT INTO CaseTable(CaseName,CaseDate,TextArea) VALUES ("'+$('#caseNameValue').val()+'", "'+$('#caseDate').val()+'","'+$('#caseTextArea').val()+'")');

//function will be called when an error occurred
function errorCB(err) {
alert("Error processing SQL: "+err.code);

//function will be called when process succeed
function successCB() {

//select all from SoccerPlayer
function queryDB(tx){
tx.executeSql('SELECT * FROM CaseTable',[],querySuccess,errorCB);

function querySuccess(tx,result){
var len = result.rows.length;

for (var i=0; i<len; i++){
'<li class="row" id="' + i + '">' + '<a href="#">' + '<img src="img/Blue-Folder.png">' + '<h2>'+result.rows.item(i).CaseName+'</h2>' + '<p>'+result.rows.item(i).CaseDate+'</p>' + '<p>'+result.rows.item(i).TextArea+'</p>'+'<span class="ui-li-count">'+ i+'</span></a>' + '</li>'


$("#Cancel").click(function() {
$.mobile.changePage($("#Home"), {
transition: "pop",
reverse: false,
changeHash: false

$("#CancelSettingButton").click(function() {
$.mobile.changePage($("#Home"), {
transition: "slide",
reverse: false,
changeHash: false

<!--<-------------------Cancel Button Functionality End----------------------------------------->-->
<!-----------------------Add Button Functionality---------------------------------------------------->

$("#AddButton").click(function() {
var isvalid=true;
$.mobile.changePage($("#Home"), {
transition: "slide",
reverse: false,
changeHash: false

Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: How to check table exit or not in db phonegap

I'm not able to tell from your code what the issue is.  However if you're looking for a helpful learning resource on how to use WebDB, here is a functional sample page (view source to see how to open, close, read, write, update and delete records):



Follow me on Twitter: @n_adam_stanley
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: How to check table exit or not in db phonegap

Just to add.


CREATE TABLE IF NOT EXISTS is a valid way to avoid recreating tables.


If you are looking for a query to strictly return whether a table exists or not, you can use something like this:


SELECT name FROM sqlite_master WHERE type='table' AND name='MyTable';


The result will be empty if it does not exist or it will contain the table if it exists.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.