# How to set the SQLite file in a specific location

**URL:** <https://forum.ionicframework.com/t/how-to-set-the-sqlite-file-in-a-specific-location/68050>\
**Category:** ionic-v3\
**Created:** [October 24, 2016, 2:08pm UTC](https://forum.ionicframework.com/t/how-to-set-the-sqlite-file-in-a-specific-location/68050 "2016-10-24T14:08:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shmu80](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@shmu80](https://forum.ionicframework.com/u/shmu80)\
**Post date:** [October 24, 2016, 2:08pm UTC](https://forum.ionicframework.com/t/how-to-set-the-sqlite-file-in-a-specific-location/68050/1 "2016-10-24T14:08:47Z")

</div>

I am using SQLite as suggested from this page [http://ionicframework.com/docs/v2/native/sqlite/](http://ionicframework.com/docs/v2/native/sqlite/)  
but how do I know where is the \*.db file location, since it set as default?  
How to set a specific db file path to location?

---

<div class="post-metadata">

**Author:** ![ruialves\_programming](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ruialves_programming/32/96340_2.png) [@ruialves\_programming](https://forum.ionicframework.com/u/ruialves_programming)\
**Post date:** [October 24, 2016, 9:22pm UTC](https://forum.ionicframework.com/t/how-to-set-the-sqlite-file-in-a-specific-location/68050/2 "2016-10-24T21:22:26Z")

</div>

> \*_but how do I know where is the .db file location, since it set as default?_

The default location is the **www** folder, so you don’t need to do anything other than placing your db file on www folder and setting `location='defalut'` on SQLite. [Image showing my DB inside www folder](http://prnt.sc/cyhglj)

* * *

* * *

In my case i’m using a pre-populated database , **don’t know if it’s what you want**.  
The plugin i’m using is (**[GitHub - brodybits/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)](https://github.com/litehelpers/cordova-sqlite-ext)**). Install with `ionic plugin add cordova-sqlite-ext --save`

Basically this what i do:

First import SQLite

> **import { SQLite } from ‘ionic-native’;**

Options to open database, name is the name of the database i already have, if you don’t have any database it should be the name to give to your DB.

> **let options = { name: “MTS.db”, location: ‘default’, createFromLocation: 1 };**

Create the connection

> **this.storage = new SQLite();**

Open database and execute a simple query (my DB contains a table called stations)

> ```
> this.storage.openDatabase(options).then((su) => {
> this.storage.executeSql('SELECT * FROM stations', {}).then((res) => {console.log(JSON.stringify(res))}, (err) => { 
> console.error('Unable to execute sql: ', err);
> });
> 
> ```

---

<div class="post-metadata">

**Author:** ![easychurch](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@easychurch](https://forum.ionicframework.com/u/easychurch)\
**Post date:** [October 28, 2019, 4:22pm UTC](https://forum.ionicframework.com/t/how-to-set-the-sqlite-file-in-a-specific-location/68050/3 "2019-10-28T16:22:56Z")

</div>

What version of Ionic are you using? In Ionic 4 did not work because it recreates the folder www.

---

<div class="post-metadata">

**Author:** ![ruialves\_programming](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ruialves_programming/32/96340_2.png) [@ruialves\_programming](https://forum.ionicframework.com/u/ruialves_programming)\
**Post date:** [October 29, 2019, 11:12am UTC](https://forum.ionicframework.com/t/how-to-set-the-sqlite-file-in-a-specific-location/68050/4 "2019-10-29T11:12:41Z")

</div>

In that case it was Ionic 2. I haven’t used Ionic since Ionic 2. I have an example with Ionic 3 in Github [ionic3-PreDB](https://github.com/iursevla/ionic3-PreDB). But i haven’t updated it in a while.

---

<div class="post-metadata">

**Author:** ![easychurch](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@easychurch](https://forum.ionicframework.com/u/easychurch)\
**Post date:** [October 29, 2019, 11:16am UTC](https://forum.ionicframework.com/t/how-to-set-the-sqlite-file-in-a-specific-location/68050/5 "2019-10-29T11:16:58Z")

</div>

Thanks man, I saw this example that you posted. But for me only version 4 same.

---

<div class="post-metadata">

**Author:** ![imgoinghamm](https://avatars.discourse-cdn.com/v4/letter/i/6bbea6/32.png) [@imgoinghamm](https://forum.ionicframework.com/u/imgoinghamm)\
**Post date:** [November 22, 2019, 12:43am UTC](https://forum.ionicframework.com/t/how-to-set-the-sqlite-file-in-a-specific-location/68050/6 "2019-11-22T00:43:01Z")

</div>

Did you ever figure this out? I am a little lost and would love some help.
