Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use an existing sqlite database in html5

I have created an sqlite database file using sqlite browser.I have a file "sample.sqlite", now i wanted to know how to import this file in javascript and use the data in the sqlite file.I have been using this below mentioned script

var db;

try {
    if (window.openDatabase) {
        db = openDatabase("sample.sqlite", "1.0", "HTML5 Database API example", 200000);
        if (!db)
            alert("Error Failed to open the database, check version");
    } else
        alert("Error Not supported? Not gonna happen");
} catch(err) {}

By using this code i am not able to get the data from sqlite file.Please suggest me how to proceed.i have seen some sites where steps have been mentioned to create table,insert data by writing code in java script itself.But i don't know to do it that way i want to import the existing sqlite file.

like image 655
user1537462 Avatar asked Mar 25 '13 11:03

user1537462


People also ask

How do I connect to an existing SQLite database?

Use the connect() method To establish a connection to SQLite, you need to pass the database name you want to connect. If you specify the database file name that already presents on the disk, it will connect to it. But if your specified SQLite database file doesn't exist, SQLite creates a new database for you.

How do I open a SQLite database in my browser?

To open the database in DB Browser do the following; Click on the 'open database' button in the toolbar. Navigate to where you have stored the database file on your local machine, select it and click open.

Can HTML5 connect to database?

HTML5 is a static document, you cannot connect to a database with HTML5, but you can use php or javascript. Show activity on this post. HTML 5 drafts used to define a couple of database systems, but they have been broken out into separate specifications (Web Storage and Web SQL Database).


1 Answers

Web apps are not allowed to access arbitrary files on the computer.

You could download some data from the same server where your JavaScript code comes from, but it would be easier and faster to embed the SQL commands to create your database in your code. (Use the .dump command of the sqlite3 command-line tool to get these SQL commands.)

like image 94
CL. Avatar answered Oct 05 '22 23:10

CL.