phonegap sqlite with prepared statement

You can insert data into SQLite Table by using prepared statement for phonegap in 4 steps as shown below.

step 1.

//Create database object

var databaseObj = null;

step 2.

// assign the Database reference

databaseObj = window.openDatabase(“TestDB”,“1.0”, “This is TestDB Database”, 200000); 

step 3.

// calling Transaction method of sqlite to insert data into InsertToEmployeeTable

databaseObj.transaction(InsertToEmployeeTable, errorDB, successDB);

step 4.

// Below InsertTOEmployeeTable  method we are inserting data from a array to EmployeeTable table

function InsertToEmployeeTable(txOne){

                    txOne.executeSql(‘DROP TABLE IF EXISTS EmployeeTable’);

                    txOne.executeSql(‘Create Table IF NOT EXISTS EmployeeTable(ID text, Name text, ContactNumber text)’);

var EmployeeArray = [“230216“, “PeterParker“, “1234567890“,“240216”, “Alex”, 0987654321″];

                    for(var position = 0; position < 2; position++){

                    var executeQuery = ‘INSERT INTO EmployeeTable(ID, Name, ContactNumber) VALUES (?, ?, ?)’;

                    txOne.executeSql(executeQuery, EmployeeArray[position+1],EmployeeArray[position+2],EmployeeArray[position+3]], function(tx, result) {

                                         alert(’Row is inserted’);



                                          alert(‘ Error occurred in EmployeeTable’);




                function errorDB(error){                    

                    alert(“Error on DB message: “+error.message+“, code: “+error.code);


                  function successDB(){

                      alert(“Everything went great..”);



Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s