Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
PhoneGap sqlite working example
Hi
I hope this helps you all get started with phonegap and sqlite in your
application
Dean-O
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!--
This is an example that shows how to create an application that uses
an embedded sqlite database
in a mobile device (iphone,ipod,ipad,android using phonegap, jquery
and sqlite.
Your phonegap project will already contain the phonegap.js.
You will need to download and add to your project the jquery.min.js
file
The application will create a database called WebSqlDb with a
table in it called User, which contains three fields UserId,
FirstName and LastName
When the application is run the firsttime, if the local database does
not exist, the application
will create the database and the table.
The application shows two text boxes which you can use to add values
to the database using the add record button
The application also has a refresh button which will get the data from
the database and show it on the screen
When the application is run on the device the onBodyLoad() function is
called, which sets up the database and table
The Add Record button calls the AddValueToDB() function
The Refresh button calls the ListDBValues() function
There are a few alert statements in this application, which are only
there for debuggin purposes. They look like this
alert("DEBUGGING: followed by some text");
These are only in the application to indicate where the application is
at when it is processing functions, etc
You will need to comment these out before you deploy/sell your
application
-->
<!-- Change this if you want to allow scaling -->
<meta name="viewport" content="width=default-width; user-
scalable=no" />
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
<title>Embedded Sql Example</title>
<!-- include the next line to use phonegap javascript functions -->
<script type="text/javascript" charset="utf-8" src="phonegap.js"></
script>
<!-- include the next line to use jquery functions in your application
you must download this and include the directory your html file is in
-->
<script type="text/javascript" charset="utf-8" src="jquery.min.js"></
script>
<!-- main scripts used in this example -->
<script type="text/javascript" charset="utf-8">
// global variables
var db;
var shortName = 'WebSqlDB';
var version = '1.0';
var displayName = 'WebSqlDB';
var maxSize = 65535;
// this is called when an error happens in a transaction
function errorHandler(transaction, error) {
alert('Error: ' + error.message + ' code: ' + error.code);
}
// this is called when a successful transaction happens
function successCallBack() {
alert("DEBUGGING: success");
}
function nullHandler(){};
// called when the application loads
function onBodyLoad(){
// This alert is used to make sure the application is loaded correctly
// you can comment this out once you have the application working
alert("DEBUGGING: we are in the onBodyLoad() function");
if (!window.openDatabase) {
// not all mobile devices support databases if it does not, the
following alert will display
// indicating the device will not be albe to run this application
alert('Databases are not supported in this browser.');
return;
}
// this line tries to open the database base locally on the device
// if it does not exist, it will create it and return a database
object stored in variable db
db = openDatabase(shortName, version, displayName,maxSize);
// this line will try to create the table User in the database just
created/openned
db.transaction(function(tx){
// you can uncomment this next line if you want the User table to be
empty each time the application runs
// tx.executeSql( 'DROP TABLE User',nullHandler,nullHandler);
// this line actually creates the table User if it does not exist
and sets up the three columns and their types
// note the UserId column is an auto incrementing column which is
useful if you want to pull back distinct rows
// easily from the table.
tx.executeSql( 'CREATE TABLE IF NOT EXISTS User(UserId INTEGER NOT
NULL PRIMARY KEY, FirstName TEXT NOT NULL, LastName TEXT NOT NULL)',
[],nullHandler,errorHandler);
},errorHandler,successCallBack);
}
// list the values in the database to the screen using jquery to
update the #lbUsers element
function ListDBValues() {
if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
return;
}
// this line clears out any content in the #lbUsers element on the
page so that the next few lines will show updated
// content and not just keep repeating lines
$('#lbUsers').html('');
// this next section will select all the content from the User table
and then go through it row by row
// appending the UserId FirstName LastName to the #lbUsers element
on the page
db.transaction(function(transaction) {
transaction.executeSql('SELECT * FROM User;', [],
function(transaction, result) {
if (result != null && result.rows != null) {
for (var i = 0; i < result.rows.length; i++) {
var row = result.rows.item(i);
$('#lbUsers').append('<br>' + row.UserId + '. ' +
row.FirstName+ ' ' + row.LastName);
}
}
},errorHandler);
},errorHandler,nullHandler);
return;
}
// this is the function that puts values into the database using the
values from the text boxes on the screen
function AddValueToDB() {
if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
return;
}
// this is the section that actually inserts the values into the User
table
db.transaction(function(transaction) {
transaction.executeSql('INSERT INTO User(FirstName, LastName)
VALUES (?,?)',[$('#txFirstName').val(), $('#txLastName').val()],
nullHandler,errorHandler);
});
// this calls the function that will show what is in the User table in
the database
ListDBValues();
return false;
}
</script>
</head>
<body onload="onBodyLoad()">
<h1>WebSQL</h1>
<input id="txFirstName" type="text" placeholder="FirstName">
<input id="txLastName" type="text" placeholder="Last Name">
<input type="button" value="Add record" onClick="AddValueToDB()">
<input type="button" value="Refresh" onClick="ListDBValues()"> <br>
<br>
<span style="font-weight:bold;">Currently stored values:</span>
<span id="lbUsers"></span>
</body>
</html>
@prashantsable

This comment has been minimized.

Show comment Hide comment
@prashantsable

prashantsable May 24, 2012

Hey thnx............it's working

Hey thnx............it's working

@AnderRasoVazquez

This comment has been minimized.

Show comment Hide comment
@AnderRasoVazquez

AnderRasoVazquez Mar 29, 2013

I will try it!

I will try it!

@chinna123

This comment has been minimized.

Show comment Hide comment
@chinna123

chinna123 Apr 20, 2013

it' not working

it' not working

@khushalchawda18

This comment has been minimized.

Show comment Hide comment
@khushalchawda18

khushalchawda18 May 10, 2013

Finally after loads of pain, found one working example. Thanks a lot!

Finally after loads of pain, found one working example. Thanks a lot!

@fakhrulzakry

This comment has been minimized.

Show comment Hide comment
@fakhrulzakry

fakhrulzakry May 18, 2013

not working :((

using xcode with phone gap. and note that the phonegap.js --> cordovaXY.js (xy is the version) and i already download query.min.js ..

not working :((

using xcode with phone gap. and note that the phonegap.js --> cordovaXY.js (xy is the version) and i already download query.min.js ..

@randori21

This comment has been minimized.

Show comment Hide comment
@randori21

randori21 Jun 13, 2013

http://inwebsite.wordpress.com say: waw! thank's
first this code not work. Then,
I read this code per line, i found that sentence comment when i copy paste was entered so i put it back then tara... it works

http://inwebsite.wordpress.com say: waw! thank's
first this code not work. Then,
I read this code per line, i found that sentence comment when i copy paste was entered so i put it back then tara... it works

@MadDevPro

This comment has been minimized.

Show comment Hide comment
@MadDevPro

MadDevPro Jun 13, 2013

Hi ! thank's for this. But i work on windows phone 8 devices. Have you got an idea ? I check on the net to resolve my problem but i didn't find a good solution. I will try nova framwork....

Thank's a lot if someone have a solution to asking database with sqlite (Phone Gap) on WP8.

Hi ! thank's for this. But i work on windows phone 8 devices. Have you got an idea ? I check on the net to resolve my problem but i didn't find a good solution. I will try nova framwork....

Thank's a lot if someone have a solution to asking database with sqlite (Phone Gap) on WP8.

@red2678

This comment has been minimized.

Show comment Hide comment
@red2678

red2678 Jun 20, 2013

I am looking for a PhoneGap Build solution for PhoneGap Storage on a Windows 8 phone.... If anyone know, I welcome feedback. Thanks!

red2678 commented Jun 20, 2013

I am looking for a PhoneGap Build solution for PhoneGap Storage on a Windows 8 phone.... If anyone know, I welcome feedback. Thanks!

@nuwancv

This comment has been minimized.

Show comment Hide comment
@nuwancv

nuwancv Jun 22, 2013

Thanks.. good example!

nuwancv commented Jun 22, 2013

Thanks.. good example!

@deividwebat

This comment has been minimized.

Show comment Hide comment
@deividwebat

deividwebat Sep 6, 2013

Uow!!! Perfect! Thanks!!

Uow!!! Perfect! Thanks!!

@panda4man

This comment has been minimized.

Show comment Hide comment
@panda4man

panda4man Sep 6, 2013

I have been looking for a good working example! thanks so much!

I have been looking for a good working example! thanks so much!

@syam22587

This comment has been minimized.

Show comment Hide comment
@syam22587

syam22587 Sep 10, 2013

Awesome....! after a lot of google search ... found this gr8 tutorial..! Thank you :)

Awesome....! after a lot of google search ... found this gr8 tutorial..! Thank you :)

@varae

This comment has been minimized.

Show comment Hide comment
@varae

varae Sep 21, 2013

I have tried the above mentioned sqlite code but after compiling, log cat shows AddValuesToDB() and ListDBValues are not defined. how to solve this? Please help me...Thanks

varae commented Sep 21, 2013

I have tried the above mentioned sqlite code but after compiling, log cat shows AddValuesToDB() and ListDBValues are not defined. how to solve this? Please help me...Thanks

@Copper087

This comment has been minimized.

Show comment Hide comment
@Copper087

Copper087 Sep 25, 2013

My problem is the same as varae; LogCat shows; Can't find variable onBodyLoad, AddValuesToDB() and ListDBValues ...

My problem is the same as varae; LogCat shows; Can't find variable onBodyLoad, AddValuesToDB() and ListDBValues ...

@Copper087

This comment has been minimized.

Show comment Hide comment
@Copper087

Copper087 Oct 9, 2013

Finally it works,.. everythink was because you have to bind in the same line sentences like:

tx.executeSql( 'CREATE TABLE IF NOT EXISTS User(UserId INTEGER NOT
NULL PRIMARY KEY, FirstName TEXT NOT NULL, LastName TEXT NOT NULL)',
[],nullHandler,errorHandler);
},errorHandler,successCallBack);

It was my fault because my javascript level is null...

Finally it works,.. everythink was because you have to bind in the same line sentences like:

tx.executeSql( 'CREATE TABLE IF NOT EXISTS User(UserId INTEGER NOT
NULL PRIMARY KEY, FirstName TEXT NOT NULL, LastName TEXT NOT NULL)',
[],nullHandler,errorHandler);
},errorHandler,successCallBack);

It was my fault because my javascript level is null...

@jordigor

This comment has been minimized.

Show comment Hide comment
@jordigor

jordigor Oct 11, 2013

Very nice post, It will be very useful. Otherwise, I have no clear where the database that is created by phonegap is stored? The database is stored at device File System or at memory?

Reading all comments I have notice that Phonegap have problems with using sqlitedb under Windows 8. Is this true? Our customer need an a mobile app that runs on different platforms (Android, Windows 8 and iOS) but it seems phonegap does not cover access to the database for all these platforms.

Kind Regards,
Jordi.

Very nice post, It will be very useful. Otherwise, I have no clear where the database that is created by phonegap is stored? The database is stored at device File System or at memory?

Reading all comments I have notice that Phonegap have problems with using sqlitedb under Windows 8. Is this true? Our customer need an a mobile app that runs on different platforms (Android, Windows 8 and iOS) but it seems phonegap does not cover access to the database for all these platforms.

Kind Regards,
Jordi.

@anushkakuvalekar

This comment has been minimized.

Show comment Hide comment
@anushkakuvalekar

anushkakuvalekar Nov 12, 2013

i getting error in null handler not define . plz any one can tell what variables to put in error handler..

i getting error in null handler not define . plz any one can tell what variables to put in error handler..

@shwetatrivedi

This comment has been minimized.

Show comment Hide comment
@shwetatrivedi

shwetatrivedi Dec 27, 2013

Hi,Thank you so much for this nice post.Its working fine.

Hi,Thank you so much for this nice post.Its working fine.

@wkuchta

This comment has been minimized.

Show comment Hide comment
@wkuchta

wkuchta Jan 9, 2014

Hi, I have this error:
01-09 13:30:57.512: E/Web Console(334): ReferenceError: Can't find variable: ListDBValues at file:///android_asset/www/dodaj.html:198

please help me.

wkuchta commented Jan 9, 2014

Hi, I have this error:
01-09 13:30:57.512: E/Web Console(334): ReferenceError: Can't find variable: ListDBValues at file:///android_asset/www/dodaj.html:198

please help me.

@dlequal

This comment has been minimized.

Show comment Hide comment
@dlequal

dlequal Feb 10, 2014

Its not working with IOS

dlequal commented Feb 10, 2014

Its not working with IOS

@joancatala

This comment has been minimized.

Show comment Hide comment
@joancatala

joancatala Feb 26, 2014

Not working on my Windows XP + Eclipse + Android:

ReferenceError: Can't find variable: $ at file:///android_asset/www/index.html:130

its seems it doesn't recognize this: $('#lbUsers').html('');

Does somebody knows why?
(I just copied and pasted it)

Not working on my Windows XP + Eclipse + Android:

ReferenceError: Can't find variable: $ at file:///android_asset/www/index.html:130

its seems it doesn't recognize this: $('#lbUsers').html('');

Does somebody knows why?
(I just copied and pasted it)

@oak-tree

This comment has been minimized.

Show comment Hide comment
@oak-tree

oak-tree Mar 23, 2014

@joancatala

seems like it doesnt find your jquery library .

From code:
include the next line to use jquery functions in your application
you must download this and include the directory your html file is in

    <script type="text/javascript" charset="utf-8" src="jquery.min.js"></

@joancatala

seems like it doesnt find your jquery library .

From code:
include the next line to use jquery functions in your application
you must download this and include the directory your html file is in

    <script type="text/javascript" charset="utf-8" src="jquery.min.js"></
@Laurence5905

This comment has been minimized.

Show comment Hide comment
@Laurence5905

Laurence5905 Apr 1, 2014

Works perfectly! Thank you so much!!! Been looking for a simple tutorial on using SQL inside a PhoneGap app. This is exactly what I needed.

To anyone who wants to use this code -- a word of warning:
The way the text is formatted on this page, some of the text is being word-wrapped to the next line. You have to put it into a text-editor and fix the bad line-breaks in the comments so they don't interfere with the code. (Lines 105/106, 113/114, 121/122 are an example of this, although there are several more.)

There are also a couple of bad line-breaks in the JavaScript code itself. For example, lines 130, 131, and 132 should all be on a single line with no line-breaks. Lines 70/71 have the same problem. There are several other examples of this problem as well.

So, because of the way the text is formatted on this site, you can't simply copy/paste and expect it to run. Take your time and go through it to fix all the weird line-breaks, and I promise you it will run. (Oh, also don't forget to download the proper jQuery-min.js file at jQuery.com. Then it will run. I promise.) :-)

Works perfectly! Thank you so much!!! Been looking for a simple tutorial on using SQL inside a PhoneGap app. This is exactly what I needed.

To anyone who wants to use this code -- a word of warning:
The way the text is formatted on this page, some of the text is being word-wrapped to the next line. You have to put it into a text-editor and fix the bad line-breaks in the comments so they don't interfere with the code. (Lines 105/106, 113/114, 121/122 are an example of this, although there are several more.)

There are also a couple of bad line-breaks in the JavaScript code itself. For example, lines 130, 131, and 132 should all be on a single line with no line-breaks. Lines 70/71 have the same problem. There are several other examples of this problem as well.

So, because of the way the text is formatted on this site, you can't simply copy/paste and expect it to run. Take your time and go through it to fix all the weird line-breaks, and I promise you it will run. (Oh, also don't forget to download the proper jQuery-min.js file at jQuery.com. Then it will run. I promise.) :-)

@tevels

This comment has been minimized.

Show comment Hide comment
@tevels

tevels Apr 8, 2014

Works great !!
Had to merge broken lines especially fix "INSERT INTO User..." line so that the sql will be on the same line

tevels commented Apr 8, 2014

Works great !!
Had to merge broken lines especially fix "INSERT INTO User..." line so that the sql will be on the same line

@Anahid

This comment has been minimized.

Show comment Hide comment
@Anahid

Anahid Apr 10, 2014

Works great! thank you! the only thing is that when you paste it from here make sure you check all lines once to see if the comments are fine and there are not additional enters. just fix them and it works great!

Anahid commented Apr 10, 2014

Works great! thank you! the only thing is that when you paste it from here make sure you check all lines once to see if the comments are fine and there are not additional enters. just fix them and it works great!

@gnganpath

This comment has been minimized.

Show comment Hide comment
@gnganpath

gnganpath Apr 11, 2014

It's Working After the code review. One line of code is comment (delete tableif already exist). Than I use phonegap1.4 and jqm1.3.2.min.js.

Working code snippet:

<title>Embedded Sql Example</title> <script type="text/javascript" charset="utf-8" src="jquery-1.3.2.min.js"></script> <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script> <script type="text/javascript" charset="utf-8"> var db; var shortName = 'WebSqlDB'; var version = '1.0'; var displayName = 'WebSqlDB'; var maxSize = 65535; function errorHandler(transaction, error) { alert('Error: ' + error.message + ' code: ' + error.code); } function successCallBack() { alert("DEBUGGING: success"); } function nullHandler(){}; function onBodyLoad(){ alert("DEBUGGING: we are in the onBodyLoad() function"); if (!window.openDatabase) { alert('Databases are not supported in this browser.'); return; } db = openDatabase(shortName, version, displayName,maxSize); db.transaction(function(tx){ //tx.executeSql( 'DROP TABLE User',nullHandler,nullHandler); tx.executeSql( 'CREATE TABLE IF NOT EXISTS User(UserId INTEGER NOT NULL PRIMARY KEY, FirstName TEXT NOT NULL, LastName TEXT NOT NULL)',[],nullHandler,errorHandler); },errorHandler,successCallBack); } function ListDBValues() { if (!window.openDatabase) { alert('Databases are not supported in this browser.'); return; } $('#lbUsers').html(''); db.transaction(function(transaction) { transaction.executeSql('SELECT * FROM User;', [],function(transaction, result) { if (result != null && result.rows != null) { for (var i = 0; i < result.rows.length; i++) { var row = result.rows.item(i); $('#lbUsers').append('
' + row.UserId + '. ' + row.FirstName+ ' ' + row.LastName); } } },errorHandler); },errorHandler,nullHandler); return; } function AddValueToDB() { if (!window.openDatabase) { alert('Databases are not supported in this browser.'); return; } db.transaction(function(transaction) { transaction.executeSql('INSERT INTO User(FirstName, LastName) VALUES (?,?)',[$('#txFirstName').val(), $('#txLastName').val()],nullHandler,errorHandler);}); ListDBValues(); return false; } </script>

WebSQL



Currently stored values:

working in eclise-phonegap-andropid

It's Working After the code review. One line of code is comment (delete tableif already exist). Than I use phonegap1.4 and jqm1.3.2.min.js.

Working code snippet:

<title>Embedded Sql Example</title> <script type="text/javascript" charset="utf-8" src="jquery-1.3.2.min.js"></script> <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script> <script type="text/javascript" charset="utf-8"> var db; var shortName = 'WebSqlDB'; var version = '1.0'; var displayName = 'WebSqlDB'; var maxSize = 65535; function errorHandler(transaction, error) { alert('Error: ' + error.message + ' code: ' + error.code); } function successCallBack() { alert("DEBUGGING: success"); } function nullHandler(){}; function onBodyLoad(){ alert("DEBUGGING: we are in the onBodyLoad() function"); if (!window.openDatabase) { alert('Databases are not supported in this browser.'); return; } db = openDatabase(shortName, version, displayName,maxSize); db.transaction(function(tx){ //tx.executeSql( 'DROP TABLE User',nullHandler,nullHandler); tx.executeSql( 'CREATE TABLE IF NOT EXISTS User(UserId INTEGER NOT NULL PRIMARY KEY, FirstName TEXT NOT NULL, LastName TEXT NOT NULL)',[],nullHandler,errorHandler); },errorHandler,successCallBack); } function ListDBValues() { if (!window.openDatabase) { alert('Databases are not supported in this browser.'); return; } $('#lbUsers').html(''); db.transaction(function(transaction) { transaction.executeSql('SELECT * FROM User;', [],function(transaction, result) { if (result != null && result.rows != null) { for (var i = 0; i < result.rows.length; i++) { var row = result.rows.item(i); $('#lbUsers').append('
' + row.UserId + '. ' + row.FirstName+ ' ' + row.LastName); } } },errorHandler); },errorHandler,nullHandler); return; } function AddValueToDB() { if (!window.openDatabase) { alert('Databases are not supported in this browser.'); return; } db.transaction(function(transaction) { transaction.executeSql('INSERT INTO User(FirstName, LastName) VALUES (?,?)',[$('#txFirstName').val(), $('#txLastName').val()],nullHandler,errorHandler);}); ListDBValues(); return false; } </script>

WebSQL



Currently stored values:

working in eclise-phonegap-andropid

@Sascuash

This comment has been minimized.

Show comment Hide comment
@Sascuash

Sascuash May 13, 2014

At least an example of database usage in phonegap that works!!! You need to change the file from js to html and look for comments that aren't commented, but after cleaning this, it works without configuring or typing any code.

I give a 10/10

At least an example of database usage in phonegap that works!!! You need to change the file from js to html and look for comments that aren't commented, but after cleaning this, it works without configuring or typing any code.

I give a 10/10

@kevininhe

This comment has been minimized.

Show comment Hide comment
@kevininhe

kevininhe Aug 31, 2014

It works perfect! Thank you very much.

It works perfect! Thank you very much.

@websunil

This comment has been minimized.

Show comment Hide comment
@websunil

websunil Sep 9, 2014

Hey Guys it works good, don't use the jquery from the internet http:// rather download it and then link the script. It works perfectly. Cheers

websunil commented Sep 9, 2014

Hey Guys it works good, don't use the jquery from the internet http:// rather download it and then link the script. It works perfectly. Cheers

@chetanRegmi

This comment has been minimized.

Show comment Hide comment
@chetanRegmi

chetanRegmi Oct 8, 2014

doesnot work :(

doesnot work :(

@Veuge

This comment has been minimized.

Show comment Hide comment
@Veuge

Veuge Nov 29, 2014

Hey!!! it works perfectly!!! Thanks!!!

But I have a problem when I want my DB to have already some data I tried:

db.transaction(function(tx){
            tx.executeSql('insert into User (FirstName, LastName) values (?,?)', ["John", "Smith"], nullHandler, errorHandler);
          });

and it works... but I don't know how to change the code for more than one data, any thoughts? help please

Veuge commented Nov 29, 2014

Hey!!! it works perfectly!!! Thanks!!!

But I have a problem when I want my DB to have already some data I tried:

db.transaction(function(tx){
            tx.executeSql('insert into User (FirstName, LastName) values (?,?)', ["John", "Smith"], nullHandler, errorHandler);
          });

and it works... but I don't know how to change the code for more than one data, any thoughts? help please

@tanotify

This comment has been minimized.

Show comment Hide comment
@tanotify

tanotify Mar 5, 2015

Finally!! It works for me like a charm!!
P.S Before using this snippet you should remove all comments (or just make them normally commented) and transfers in sql request.

tanotify commented Mar 5, 2015

Finally!! It works for me like a charm!!
P.S Before using this snippet you should remove all comments (or just make them normally commented) and transfers in sql request.

@rashid183

This comment has been minimized.

Show comment Hide comment
@rashid183

rashid183 Mar 31, 2015

Wonderful example. Works fine for me. Where can i find the database file in my device ?

Wonderful example. Works fine for me. Where can i find the database file in my device ?

@tejasghutukade

This comment has been minimized.

Show comment Hide comment
@tejasghutukade

tejasghutukade May 25, 2015

How to store the database in a specific location...

How to store the database in a specific location...

@apachiweb

This comment has been minimized.

Show comment Hide comment
@apachiweb

apachiweb Oct 28, 2015

How to upload the database detail to web server or export it in csv or excel

How to upload the database detail to web server or export it in csv or excel

@sekinat

This comment has been minimized.

Show comment Hide comment
@sekinat

sekinat Dec 9, 2015

please I think there is a problem with this line $('#lbUsers').html('');. The data in the database is not showing when i click refresh. I need help pls.

sekinat commented Dec 9, 2015

please I think there is a problem with this line $('#lbUsers').html('');. The data in the database is not showing when i click refresh. I need help pls.

@NikDrosakis

This comment has been minimized.

Show comment Hide comment
@NikDrosakis

NikDrosakis Dec 20, 2015

sqlite is.... websql????

sqlite is.... websql????

@MahdiMajidzadeh

This comment has been minimized.

Show comment Hide comment
@MahdiMajidzadeh

MahdiMajidzadeh Dec 30, 2015

nice! thanks :)

nice! thanks :)

@sek123

This comment has been minimized.

Show comment Hide comment
@sek123

sek123 Jan 8, 2016

Its now working, Thanks.

sek123 commented Jan 8, 2016

Its now working, Thanks.

@kalanidhiSBU

This comment has been minimized.

Show comment Hide comment
@kalanidhiSBU

kalanidhiSBU Mar 7, 2016

Is it possible to use serial data type in sqlite data base?

Is it possible to use serial data type in sqlite data base?

@atul789

This comment has been minimized.

Show comment Hide comment
@atul789

atul789 Mar 10, 2016

Does not seem to be working for me, throwing the error in alert box: Error could not prepare statement(1 no such table:User)code:5. I have copy pasted the same code given above and inserted required '.js' files. I am working on windows machine with phonegap installed on it.

atul789 commented Mar 10, 2016

Does not seem to be working for me, throwing the error in alert box: Error could not prepare statement(1 no such table:User)code:5. I have copy pasted the same code given above and inserted required '.js' files. I am working on windows machine with phonegap installed on it.

@the-RedHerring

This comment has been minimized.

Show comment Hide comment
@the-RedHerring

the-RedHerring Apr 15, 2016

Got it to work with little effort!!! @atul789, I actually saw the same error you did the first go and it was because I missed one of the errant line breaks in one of the comments in the onBodyLoad function. After I fixed that, it added the User table as designed. I would look back over your code for any improper line breaks if you haven't already.

Thanks so much for this example! I never realized so much potential was available using html5 app development and now I'm really excited to get started.

Got it to work with little effort!!! @atul789, I actually saw the same error you did the first go and it was because I missed one of the errant line breaks in one of the comments in the onBodyLoad function. After I fixed that, it added the User table as designed. I would look back over your code for any improper line breaks if you haven't already.

Thanks so much for this example! I never realized so much potential was available using html5 app development and now I'm really excited to get started.

@Kalyan14

This comment has been minimized.

Show comment Hide comment
@Kalyan14

Kalyan14 Apr 30, 2016

Will it work for cordova ?

Will it work for cordova ?

@wchikatala

This comment has been minimized.

Show comment Hide comment
@wchikatala

wchikatala May 3, 2016

Any version of the same using javascript and not jquery?

Any version of the same using javascript and not jquery?

@kerryf88

This comment has been minimized.

Show comment Hide comment
@kerryf88

kerryf88 Aug 30, 2016

It doesn't work for me. When I click Add record or Refresh the data is not entered into the database. I've already modified all the lines etc

It doesn't work for me. When I click Add record or Refresh the data is not entered into the database. I've already modified all the lines etc

@glasner1982

This comment has been minimized.

Show comment Hide comment
@glasner1982

glasner1982 Sep 16, 2016

Finally after a week of aggravation i got this to work lol. For anyone still puzzled, you need to reformat a lot of the javascript, comment some lines out, etc. Also, make sure you download and include jquery-3.1.0.min.js and jquery-3.1.0.js in your project folder and reference them in the index.html file.

Now i have a question. I changed the <span> tag to a <ul> tag with the same id and it works, displaying as a numberd list. Cool. How can I have the entries in the <ul> be links that I can click on to show that specific entry? In my form, i'm catpuring more than 2 field entries, but only want to show 1 field value in the list, then when the user clicks on that specific entry, it shows the whole entry (I hope that makes sense).

For example, user enters name, address and phone number, all entries get inserted into table but the <ul> would only show the name. then user clicks on a name and it will show the whole entry (name, address, phone) Anyone have any ideas? Thanks in advance :)

Finally after a week of aggravation i got this to work lol. For anyone still puzzled, you need to reformat a lot of the javascript, comment some lines out, etc. Also, make sure you download and include jquery-3.1.0.min.js and jquery-3.1.0.js in your project folder and reference them in the index.html file.

Now i have a question. I changed the <span> tag to a <ul> tag with the same id and it works, displaying as a numberd list. Cool. How can I have the entries in the <ul> be links that I can click on to show that specific entry? In my form, i'm catpuring more than 2 field entries, but only want to show 1 field value in the list, then when the user clicks on that specific entry, it shows the whole entry (I hope that makes sense).

For example, user enters name, address and phone number, all entries get inserted into table but the <ul> would only show the name. then user clicks on a name and it will show the whole entry (name, address, phone) Anyone have any ideas? Thanks in advance :)

@kdizel21

This comment has been minimized.

Show comment Hide comment
@kdizel21

kdizel21 Sep 16, 2016

Thanks so much. Works perfectly

Thanks so much. Works perfectly

@Hashtag1147

This comment has been minimized.

Show comment Hide comment
@Hashtag1147

Hashtag1147 Nov 5, 2016

This works great after the code edits, I have been scouring the internet but to no avail.
Thanks so much.

This works great after the code edits, I have been scouring the internet but to no avail.
Thanks so much.

@Danielsvt

This comment has been minimized.

Show comment Hide comment
@Danielsvt

Danielsvt Jan 20, 2017

In my cordova 6.3x, it wasn't working and I was intrigued once it was working in both safari and chrome. So I read the other day about how the onClick= method was unstable, and I remove them from the inputs and wrapped all the inputs in a single form with a POST method and a submit button. Voi lá! Great code, thanks man, really appreciate.

In my cordova 6.3x, it wasn't working and I was intrigued once it was working in both safari and chrome. So I read the other day about how the onClick= method was unstable, and I remove them from the inputs and wrapped all the inputs in a single form with a POST method and a submit button. Voi lá! Great code, thanks man, really appreciate.

@dgk4201

This comment has been minimized.

Show comment Hide comment
@dgk4201

dgk4201 Jul 28, 2017

Works great. Has anyone converted this to SQLite/phonegap? I have an existing SQLite db I want to access via a phonegap app.

dgk4201 commented Jul 28, 2017

Works great. Has anyone converted this to SQLite/phonegap? I have an existing SQLite db I want to access via a phonegap app.

@vegeth1985

This comment has been minimized.

Show comment Hide comment
@vegeth1985

vegeth1985 Dec 28, 2017

hi, this example work good but i need that create a file .sql ... now i think that this database is in cache? i need a file db.sql

hi, this example work good but i need that create a file .sql ... now i think that this database is in cache? i need a file db.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment