0

i am new in android phonegap application. i try one phonegap application in android, here i create one database and table and insert value using javascript its working fine, now i want to retrieve database value in android native. here my code

my javascript code:

function loaddb()
{
var db = openDatabase(‘testdb’, ’1.0′, ‘my database’, 2 * 1024 * 1024);

db.transaction(function (tx)
{
tx.executeSql(‘CREATE TABLE IF NOT EXISTS person (_id INTEGER, person_name TEXT, address TEXT)’);

tx.executeSql(‘INSERT INTO person (_id, person_name, address) VALUES(1, “Hardik Trivedi”, “Ahmedabad,Gujarat,India”)’);
tx.executeSql(‘INSERT INTO person (_id, person_name, address) VALUES(2, “Sonam Kapoor”, “Mumbai,Maharashtra,India”)’);
tx.executeSql(‘INSERT INTO person (_id, person_name, address) VALUES(3, “Rajnikanth”, “There is no specific address of him :) “)’);

});
}


my html code:


<html>
<head>
<script src=”db.js”></script>
<script src=”jquery.js”></script>

</head>
<body>
<div>
<script language=”javascript”>
$(document).ready(function() {
alert(“Hello”);
loaddb();
});
</script>
</div>
<h4>Hello Friends !!!!!!</h4>
</body >

</html>

any possibility is there to retrieve this javascript database in android?

1 Answer 1

2
<!DOCTYPE HTML>
 <html>
<head>
<script type="text/javascript">
var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
 var msg;
 db.transaction(function (tx) {
 tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
 tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "foobar")');
  tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "logmsg")');
 msg = '<p>Log message created and row inserted.</p>';
 document.querySelector('#status').innerHTML =  msg;
});

db.transaction(function (tx) {
tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
var len = results.rows.length, i;
msg = "<p>Found rows: " + len + "</p>";
document.querySelector('#status').innerHTML +=  msg;
for (i = 0; i < len; i++){
 msg = "<p><b>" + results.rows.item(i).log + "</b></p>";
 document.querySelector('#status').innerHTML +=  msg;
  }
   }, null);
 });
   </script>
</head>
 <body>
  <div id="status" name="status">Status Message</div>
 </body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

i want this select statement in android native, is it possible? create and insert using javascript and select statement should be placed in android native.
I need the instance of the database created through javascript in android native, so that i could access to its table in android.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.