tags:

views:

135

answers:

2

Would it be possible to programmaticly create a data source in jboss and still have a valid jndi entry for the entity manager to use?

Creating the data source is where I am lost, I hope I can use a MBean that runs on stat-up to handle this.

This would not be my preferred method, but the application I am working on has a global configuration file hosted on another server I am suppose to use for configuration.

update: In this instance I need to create a data source programticly or change the jdbc url of an exsiting datasource. I don't know the DB server url until runtime.

A: 

Here's a post that describes how to create a jboss service archive (SAR) that you can put in your EAR that will deploy a data source when the EAR is deployed, and remove it when the EAR in undeployed.

karoberts
+1  A: 

Rather than poking around in the guts of JBoss in order to do this, I suggest using a 3rd-party connection pool utility, such as Apache Commons DBCP. There are instructions on how to programmatically register a DBCP datasource on JNDI here.

The first two lines of the sample code should be unnecessary, just create the default InitialContext and then rebind the datasource reference into it as described.

skaffman