JBoss 6 : Retrieve list of configured datasources at runtime

Introduction

Working with database connections on enterprise application servers like JBoss is in 99.9% very simple and well standardized. What one needs to do is:

  1. Configure datasources (*-DS.xml files)
  2. Configure persistence units in persistence.xml file
  3. Use dependency injection (@PersistenceContext(unitName=”pUnit”)) in order to obtain EntityManager

, and voilà: you are ready to work with defined databases. In your code you do not need to create any database connections or bother what is the name of database, username/password as well as datasource name. However, there is this 0.1% of cases in which your application is  extraordinary (been there 😉 ) and you need to have some more information and control over db-layers or you just simply need it for some reason I cannot even imagine 🙂 If you do, in this post you will find how to retrieve a list of available datasources.

Read more of this post

Advertisements