General J2EE: How to dynamically configure a datasource

  1. How to dynamically configure a datasource (3 messages)

    Hi, I have a web application requiring to connect to one of several SQL Server databases. They are all identical in structure; what changes is the IP address, user and password. I am using JBoss; so far I had configured datasources in a static way as -ds.xml files in the app server deploy directory. But in this case I don't know the connection parameters in advance: they are discovered at runtime depending on the user who logs in. Is there any standard way to dynamically setup a javax.sql.Datasource object and do the JNDI binding at runtime? Can this code be independent of the application server being used? Thanks

    Threaded Messages (3)

  2. As far a I know, you cannot just change the whole datasource at run time. What you can do is, create datasources for all the databases you have and they will have the jndi binding. Now according to the user input, you can look up different datasources. This will anyway solve your problem. cheers, http://javaicillusion.blogspot.com/
  3. Yes, you can[ Go to top ]

    Imagine that you are in Java SE environment (where you can create JDBC connections and datasources manually), then (don't forget completely about Java EE ;)) bind/rebind the newly created datasource to JNDI under the same name (so your apps will see it).
  4. Re: Yes, you can[ Go to top ]

    Offcourse, you can bind unbind and also rebind resources under same name dynamically, but how far will it scale. And binding with existing name is skeptical. cheers,