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.
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.
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.
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).
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With