Dynamically assign resource for database in Java based web application
<p>I'm playing java based web application recently. Here is a barrier that I couldn't figure it out for long period. Hope someone can give some hints. </p>

<p>In my case, I used two xml files for pre-configuration. One is database resources' details include URLs, usernames, passwords and so on while the another one is simple selection options for DOM later. The purpose I want to use xml files for pre-configuration is to make my program as dynamic as possible. Hence, any updated in one of my database, I can just change the two xml files instead of the source codes. </p>

<p>In order to achieve that, I needed to dynamically assign database resource based user's selection. My personal idea to obtain this goal is through following procedures in Controller or Servlet class:</p>

<pre><code>// get user's selected option from request, create Input object       
String userSelection = request.getParameter("title");
Input userInput = new Input(userSelection);     

// open user selection options xml inside Input class
Document doc = dBuilder.parse(xmlFile); 

// get matched option and set database name inside Input class
if(userSelectoin.equals(doc.getElementByTagName("desiredTitle"))
{
   userInput.setDB(doc.getElementByTagName("dbname");  
}

// use resource injection to get all details of corresponding database in database xml
@Resource(name=userInput.getDB())
public void doConnection()
{
   DataSource myDB;
   Connection myConn = myDB.getConnection(); 
}
</code></pre>

<p>The barrier lies at the fourth procedure. For resource injection, its name needs constant string such as <code>@Resource(name="myDB1")</code>. However the tradeoff is it may make program not dynamic at all. My query will be how to set and get final String in java or is there any other possible solution to get my goal ?</p>

<p>The error message from Eclipse is "The value for annotation attribute Resource.name must be a constant expression".    </p>
