SQLite

Use SQLite as the JobRunr StorageProvider - driver dependency, configuration, and table creation.

On this page

JobRunr stores all background jobs in SQLite through the SqLiteStorageProvider. JobRunr is tested against sqlite-jdbc version 3.47.2.0.

Note

SQLite is an excellent embedded database - it ships with Android, iOS, macOS and most Linux distributions, which makes it a natural fit for mobile and desktop applications. It is serverless and file-based by design though, so there is no cluster mode: background job servers on different machines cannot share a SQLite database.

Add the driver dependency

Add the SQLite JDBC driver to your project. The latest version is on Maven Central.

<dependency>
  <groupId>org.xerial</groupId>
  <artifactId>sqlite-jdbc</artifactId>
  <version><!-- latest version --></version>
</dependency>

Configuration

If you use a framework starter, JobRunr automatically detects your existing DataSource - configure your database the usual way and you are done.

HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:sqlite:./data/mydb.sqlite");
DataSource dataSource = new HikariDataSource(config);

JobRunr.configure()
    .useStorageProvider(SqlStorageProviderFactory.using(dataSource))
    .useBackgroundJobServer()
    .initialize();

Creating the tables

By default JobRunr creates its tables automatically. If you want to create them yourself, use the DatabaseCreator or generate the SQL scripts with migration type sqlite. See Setting up an SQL database.

Next steps

Looking for another database? Back to the Storage overview.