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>
Recommended Articles
Create and Configure DataSource with WildFly Application Server Using CLI
Learn how to create a DataSource for PostgreSQL in WildFly using CLI. Includes configuring and injecting it into a Java application.
Troubleshooting WildFly DataSource Connection Leaks and Pool Management
Fixing connection leaks and optimizing WildFly DataSource pool size for seamless database access. #Java #WildFly #DatabaseConnection
Configure MS SQL Server Datasource on WildFly Application Server
Learn how to configure Microsoft SQLServer Datasource on WildFly application server with step-by-step instructions and examples.
Deploy WildFly Datasource XML File for Java EE Applications: A Comprehensive Guide
Learn how to deploy a WildFly datasource XML file in your Java EE application with step-by-step instructions and best practices.