In JBoss 3.0.0 you can drop the xml file describing the datasource in the deploy directory and JBoss will configure it.
In your scenario, this would involving creating a XML document containing configuration for the database and then writing this document to the deploy directory.
As I have indicated in numerous posts in the past, in 2.4 and 3 you can also construct the appropriate mbean in code. A requently run example for 3 is in the DataSourceLoaderUnitTestCase in .../test/jmx/tests. Of course, such configuration will not persist over jboss restarts.
For 2.4.x I once posted a patch "making configuration service a deployer" as I recall that let you deploy xml bits while jboss is running.