Chapter 1. Introduction to using data sources with Quarkus
1.1. Setting the db-kind property for a data source Copy linkLink copied to clipboard!
When you set the db-kind property in the configuration file of your application to match the type of your data source that you want to use, Quarkus automatically resolves the appropriate type of database driver. The following procedure demonstrates how you can set the db-kind property for a data source.
Prerequisites
- You have a Quarkus Maven project.
Procedure
- Navigate to your Quarkus project directory.
In the
src/main/resources/application.propertiesfile, set the value of thedb-kindproperty to match the type of the data source that you want to use. The following example usespostgresqlas the data source type:quarkus.datasource.db-kind=postgresql
quarkus.datasource.db-kind=postgresqlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.2. Setting database credentials Copy linkLink copied to clipboard!
You can define credentials that your application uses to access your database. Defining access credentials for your database is optional. You can skip this procedure when configuring a data source for your application.
Prerequisites
- You have a Quarkus Maven project.
-
You have set the
db-kindproperty for your data source. - Your Quarkus application is in JVM mode. This prerequisite applies when you use a JDBC driver that Quarkus does not support in native mode.
Procedure
- Navigate to your Quarkus project directory.
In the
src/main/resources/application.propertiesfile, set the value of thequarkus.datasource.usernameproperty to match the username that your application uses to access the database:quarkus.datasource.username=<username>
quarkus.datasource.username=<username>Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the
src/main/resources/application.propertiesfile, set the value of thequarkus.datasource.passwordproperty to match the password that your application uses to access the database:quarkus.datasource.password=<password>
quarkus.datasource.password=<password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.3. Quarkus driver extensions for built-in databases Copy linkLink copied to clipboard!
The following table provides an overview of Quarkus built-in databases and the extensions that you can use to connect your application to a relational database:
| Database built-in | db-kind | Agroal extension | Reactive extension |
|---|---|---|---|
| DB2 |
|
|
|
| Derby |
|
| N/A |
| H2 |
|
| N/A |
| MariaDB |
|
|
|
| Microsoft SQL Server |
|
| N/A |
| MySQL |
|
|
|
| PostgreSQL |
|
|
|
You can configure H2 and Derby databases to run in embedded mode. The H2 and Derby driver extensions do not support compiling the embedded database engine into native executables.
This table includes supported and community artifacts. For a list of supported Maven artifacts, see the Red Hat build of Quarkus Component Details page.
When you use one of the built-in database kinds the JDBC driver resolves automatically to the following values:
| Database | JDBC driver | XA driver |
|---|---|---|
| DB2 |
|
|
| Derby |
|
|
| H2 |
|
|
| MariaDB |
|
|
| Microsoft SQL Server |
|
|
| MySQL |
|
|
| PostgreSQL |
|
|
You can configure H2 and Derby databases to run in embedded mode. The H2 and Derby driver extensions do not support compiling the embedded database engine into native executables.