# Read Existing SQLite Database File and Load Data

**URL:** <https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167>\
**Category:** Ionic Native\
**Created:** [June 13, 2017, 5:10pm UTC](https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167 "2017-06-13T17:10:38Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Nejthe](https://avatars.discourse-cdn.com/v4/letter/n/838e76/32.png) [@Nejthe](https://forum.ionicframework.com/u/Nejthe)\
**Post date:** [August 9, 2017, 8:29am UTC](https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167/10 "2017-08-09T08:29:50Z")

</div>

First of all, you need to import 3 plugins:

> **[an-rahulpandey/cordova-plugin-dbcopy](https://github.com/an-rahulpandey/cordova-plugin-dbcopy)**
>
> cordova-plugin-dbcopy - Copy SQLite Database from www folder to default app database location

> **[litehelpers/Cordova-sqlite-storage](https://github.com/litehelpers/Cordova-sqlite-storage)**
>
> Cordova-sqlite-storage - A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API

> **[litehelpers/cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext)**
>
> cordova-sqlite-ext - A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/macOS/Windows with REGEXP (Android/macOS/iOS) and pre-populated databases (Android/iOS/macOS/Windows)

Then import the SQLite in your ts file:

```auto
import { Component } from '@angular/core';
import { SQLite } from "ionic-native";
import { Platform, NavController, PopoverController } from 'ionic-angular';

```

```auto

export class HomePage {
    public storage: SQLite;
    public itemList: Array<Object>;

```

```auto
 constructor(public popoverCtrl: PopoverController, public navCtrl: NavController, public platform: Platform) {

   this.itemList = [];

        this.platform.ready().then(() => {
            this.storage = new SQLite();
            this.storage.openDatabase({ name: "data.db", location: 'default', createFromLocation: 1 }).then((success) => {
                this.storage.executeSql("SELECT * FROM art", {}).then((data) => {
                    let rows = data.rows;
                    for (let i = 0; i < rows.length; i++) {
                        this.itemList.push({
                            id: rows.item(i).id
                        });
                    }
                }, (error) => {
                    console.info("Unable to execute sql " + JSON.stringify(error));
                })
         }, (err) => {
                console.info("Error opening database: " + err);
            });
        });
    }

```

Don’t forget to add the file data.db in www/ directory.

I hope I didn’t miss anything. Let me know if it works.

---

_[View the full topic](https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167)._
