= Datasources

Provides support for container-managed database connections.

== Autodetectable drivers

If your application includes the appropriate vendor JDBC
library in its normal dependencies, these drivers will be detected
and installed by {Thorntail} without any additional effort.

The list of detectable drivers and their `driver-name` which
may be used when defining a datasource is as follows:

[cols="2*", options="header"] 
|===
|Database
|`driver-name`

|MySQL
|`mysql`

|PostgreSQL
|`postgresql`

|H2
|`h2`

|EnterpriseDB
|`edb`

|IBM DB2
|`ibmdb2`

|Oracle DB
|`oracle`

|Microsoft SQLServer
|`sqlserver`

|Sybase
|`sybase`

|Teiid
|`teiid`

|MariaDB
|`mariadb`

|Derby
|`derby`

|Hive2
|`hive2`

|PrestoDB
|`prestodb`
|===

== Example datasource definitions

=== MySQL

An example of a MySQL datasource configuration with connection information, basic security, and validation options:

[source,yaml,options="nowrap"]
----
thorntail:
  datasources:
    data-sources:
      MyDS:
        driver-name: mysql
        connection-url: jdbc:mysql://localhost:3306/jbossdb
        user-name: admin
        password: admin
        valid-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker
        validate-on-match: true
        background-validation: false
        exception-sorter-class-name: org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter
----

=== PostgreSQL

An example of a PostgreSQL datasource configuration with connection information, basic security, and validation options:

[source,yaml,options="nowrap"]
----
thorntail:
  datasources:
    data-sources:
      MyDS:
        driver-name: postgresql
        connection-url: jdbc:postgresql://localhost:5432/postgresdb
        user-name: admin
        password: admin
        valid-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker
        validate-on-match: true
        background-validation: false
        exception-sorter-class-name: org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter
----

=== Oracle

An example of an Oracle datasource configuration with connection information, basic security, and validation options:

[source,yaml,options="nowrap"]
----
thorntail:
  datasources:
    data-sources:
      MyDS:
        driver-name: oracle
        connection-url: jdbc:oracle:thin:@localhost:1521:XE
        user-name: admin
        password: admin
        valid-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker
        validate-on-match: true
        background-validation: false
        stale-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker
        exception-sorter-class-name: org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter
----

