How to inject a Datasource in your Enterprise applications

To inject a Datasource in your Enterprise applications you can use the javax.annotation.Resource annotation to declare a reference to that resource. The @Resource can decorate a class, a field, or a method. The container will inject the resource referred to by @Resource into the component either at runtime or after its initialization. In the following … Read more

How do you connect a Datasource to a Cluster ?

When connecting WildFly / JBoss EAP to a Database cluster you need to provide an appropriate JDBC Connection String. We’ll examine three popular Database: Oracle, MySQL and PostgreSQL. Oracle Real Application Clusters (RAC) Oracle Real Application Clusters (RAC) is a software component you can add to a high-availability solution that enables users on multiple machines … Read more

How to connect to a DataSource from a remote client?

WildFly and JBoss EAP 6/7 no longer support remote JNDI lookup of datasource objects. If you attempt to lookup a Datasource object from a remote client, the following error will be thrown: ERROR: org.jboss.remoting3.MessageCancelledException Exception in thread “main” org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is java.io.NotSerializableException: org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] As an alternative, it is recommend using an … Read more

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 … Read more

JBoss run out of Connections ? here is how to fix it

Have you got No ManagedConnections available error message ? … javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/MyDataSource … javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (30000 [ms]) In this tutorial we will learn which are the possible causes to this problem. # 1  Your connection pool is too small Increase … Read more

JBoss Datasource HA configuration made simple

JBoss / WildFly Datasource High availability was a feature available in older JBoss AS versions (namely JBoss AS 4 and 5). The current version of the application server still allows to use some HA strategies, although the best practice to implement HA at Database level, by clustering your Database. Clustering the Database refers to the ability … Read more

How to trace JDBC statements with JBoss and WildFly

This tutorial covers how to trace JDBC Statements running on the top of WildFly application server or JBoss Enterprise Application Platform. There are multiple ways to trace SQL Statements: Use Hibernate/JPA properties (if your application is using it) Configure P6Spy tool on WildFly (if you are issuing plain SQL Statements) Configure your JDBC Driver to … Read more

Configuring MS SQLServer Datasource in WildFly

In this tutorial we will learn how to configure Microsoft SQLServer Datasource on WildFly application server First of all, you need a JDBC Driver which is fit for your SQLServer version. You can download the JDBC Driver from Microsoft’s site: https://docs.microsoft.com/en-us/sql/connect/jdbc/microsoft-jdbc-driver-for-sql-server Some popular options include: mssql2017: mssql-jdbc-7.4.1.jre8.jar mssql2016: mssql-jdbc-6.4.0.jre8.jar Then, from the jboss-cli.sh connect and … Read more

How do I access the specific driver Connection with JBoss ?

If you need to access to the specific driver connection (for example the OracleConnection instead of the java.sql.Connection) then you need to use the WrappedConnection object and get its underlying connection: Connection c = dataSource.getConnection(); org.jboss.resource.adapter.jdbc.WrappedConnection wc = (WrappedConnection) c; OracleConnection ajc = (OracleConnection ) wc.getUnderlyingConnection(); Please note this class is available in the ironjacamar-jdbc-1.x.xx.Final.jar module … Read more