How to add Connection properties to your JBoss DataSource ?

In this article we will learn how to configure Connection Properties in a JBoss / WildFly Datasource.

Let’s step back first. To configure Connection Pooling (non-XA) to a Database you have two options:

  • Using a class which implements java.sql.Driver
  • Using a class which implements javax.sql.DataSource

When using a Class which implements java.sql.Driver, you can simply add a connection-property element in your datasource as in this example:

<datasource jndi-name="java:/comp/env/jdbc/mysqlantoioviDB" pool-name="MysqlPools" enabled="true" use-java-context="true">
                <connection-url>jdbc:mysql://localhost:3306/demoDB</connection-url>
             
                <connection-property name="vendorProperty">value</connection-property>

                <driver>mysql</driver>
                <security>
                    <user-name>sa</user-name>
                    <password>sa</password>
                </security>
                <pool>
                    <max-pool-size>30</max-pool-size>
                </pool>
</datasource>

When using a class which implements javax.sql.DataSource, add a Property named “ConnectionProperties” with a comma separated list of properties. Example:

<datasource jndi-name="java:/comp/env/jdbc/mysqlantoioviDB" pool-name="MysqlPools" enabled="true" use-java-context="true">
                <connection-url>jdbc:mysql://localhost:3306/demodb</connection-url>
             
                <connection-property name="ConnectionProperties">property1=value,property2=valueTwo</connection-property>


                <driver>mysql</driver>
                <security>
                    <user-name>sa</user-name>
                    <password>sa</password>
                </security>
                <pool>
                    <max-pool-size>30</max-pool-size>
                </pool>
</datasource>

On the other hand, for XA Datasources, you can set Properties as follows:

<xa-datasource-property name="ConnectionProperties">property1=value,property2=vaue2</xa-datasource-property>

 

Found the article helpful? if so please follow us on Socials