<meta name="viewport" content="width=device-width, user-scalable=no">
<script type="text/javascript" charset="utf-8" src="components/loader.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.alert("Create a database and display the content");
function executeQuery(tx) {
tx.executeSql('DROP TABLE IF EXISTS TestTable');
tx.executeSql('CREATE TABLE IF NOT EXISTS TestTable (id unique, data)');
tx.executeSql('INSERT INTO TestTable (id, data) VALUES (1, "あいうえお")');
tx.executeSql('INSERT INTO TestTable (id, data) VALUES (2, "かきくけこ")');
tx.executeSql('INSERT INTO TestTable (id, data) VALUES (3, "さしすせそ")');
tx.executeSql('INSERT INTO TestTable (id, data) VALUES (4, "たちつてと")');
tx.executeSql('INSERT INTO TestTable (id, data) VALUES (5, "なにぬねの")');
tx.executeSql('INSERT INTO TestTable (id, data) VALUES (6, "はひふへほ")');
tx.executeSql('INSERT INTO TestTable (id, data) VALUES (7, "まみむめも")');
tx.executeSql('SELECT * FROM TestTable', [], querySuccess, errorCB);
function querySuccess(tx, results) {
var len = results.rows.length;
window.alert("There are " + len + " rows of records in the database.");
for (var i=0; i<len; i++){
document.writeln("row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data+"<br/>");
//Callback function when the transaction is failed.
console.log("Error occured while executing SQL: "+err.code);
// Callback function when the transaction is success.
var db = window.openDatabase("Database", "1.0", "TestDatabase", 200000);
db.transaction(queryDB, errorCB);
var db = window.openDatabase("Database", "1.0", "TestDatabase", 200000);
db.transaction(executeQuery, errorCB, successCB);
<input type="button" value="Execute SQL transactions" onclick="createDB()">