# Database

Database stores the documents' data. It's mandatory to have `db.dat` file if type of the document, OCR zone information should be recognized. If MRZ, Barcode recognition or image cropping are used, there is no need to have the `db.dat` file.

{% hint style="info" %}
After db.dat is added, it'll be unpacked and a few new files will be created.
{% endhint %}

The options to get the `db.dat` file are presented below.

## Adding database manually

You can manually add database to the project. First of all, follow the next link [licensing.regulaforensics.com](https://licensing.regulaforensics.com/), select page "Databases" and download `db.dat` file. After this you need to create `assets` and `Regula` folders in your project and add `db.dat` file to `app/src/main/assets/Regula` folder.

## Adding database using prepareDatabase method

To reduce your package size database (`db.dat` file) can be obtained from the network. In order to download `db.dat` file you should know its identifier, all database identifiers you can find on <https://licensing.regulaforensics.com>.

{% tabs %}
{% tab title="Java" %}

```java
DocumentReader.Instance().prepareDatabase(MainActivity.this, "Full", new IDocumentReaderPrepareCompletion() {
    @Override  
    public void onPrepareProgressChanged(int progress) {  
        // getting progress
    }  

    @Override  
    public void onPrepareCompleted(boolean status, Throwable error) {  
        // database was prepared
    }  
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DocumentReader.Instance().prepareDatabase(this@MainActivity, "Full", object : IDocumentReaderPrepareCompletion {
    override fun onPrepareProgressChanged(progress: Int) {
        // getting progress
    }
        
    override fun onPrepareCompleted(status: Boolean, error: Throwable?) {
        // database was prepared
    }
})
```

{% endtab %}
{% endtabs %}

When operation is completed successfully, `db.dat` file will get to resources in the same way as if you add it manually. This operation should be run before initialization process.

## Adding database using runAutoUpdate method

For getting always the latest version of database you can run autoupdate function:

{% tabs %}
{% tab title="Java" %}

```java
DocumentReader.Instance().runAutoUpdate(MainActivity.this, "Full", new IDocumentReaderPrepareCompletion() {
    @Override  
    public void onPrepareProgressChanged(int progress) {  
        // getting progress
    }  

    @Override  
    public void onPrepareCompleted(boolean status, Throwable error) {  
        // database was prepared
    }  
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DocumentReader.Instance().runAutoUpdate(this@MainActivity, "Full", object : IDocumentReaderPrepareCompletion {
    override fun onPrepareProgressChanged(progress: Int) {
        // getting progress
    }
        
    override fun onPrepareCompleted(status: Boolean, error: Throwable?) {
        // database was prepared
    }
})
```

{% endtab %}
{% endtabs %}

When operation is completed successfully, `db.dat` file will get to resources after update and will be used in next initialization.

## Removing database using removeDatabase method

Allows to remove the added database:

{% tabs %}
{% tab title="Java" %}

```java
DocumentReader.Instance().removeDatabase(MainActivity.this);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DocumentReader.Instance().removeDatabase(this@MainActivity)
```

{% endtab %}
{% endtabs %}

## Cancelling database update

Allows to cancel database update:

{% tabs %}
{% tab title="Java" %}

```java
DocumentReader.Instance().cancelDBUpdate();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DocumentReader.Instance().cancelDBUpdate()
```

{% endtab %}
{% endtabs %}
