title: Updating URL of DataSource object for JDBC connection
body: <p>I have a situation where I am on a server with a valid DataSource file (reproduced below) for connection to a local database which works fine.  I also have a host of other machines with the exact same credentials except their ip addresses are different (which I also have).  I would like to read in my localhost DataSource object and update the connection url with a different ipaddress.  How do I do this?  I'm using JBoss 4.2.3 for my deployment (which I cannot change).</p>
  
  <p>Here is the method that I would like to create</p>
  
  <pre><code>/**
   * This gets a DataSource for a specified IP address using pacsDS as a template.
   * @param ipaddress
   * @return 
   */
  public static DataSource getDataSource(Context context, String ipaddress) throws NamingException {
      DataSource ds = (DataSource)context.lookup("java:/pacsDS");
      // Update ds to make use of supplied ipaddress
      // ...
      return ds;
  }
  </code></pre>
  
  <p>Here is the data source xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;!-- ===================================================================== --&gt;
  &lt;!--                                                                       --&gt;
  &lt;!--  JBoss Server Configuration                                           --&gt;
  &lt;!--                                                                       --&gt;
  &lt;!-- ===================================================================== --&gt;
  
  &lt;!-- $Id: pacs-postgres-ds.xml 5174 2007-09-26 21:05:41Z gunterze $ --&gt;
  &lt;!-- ==================================================================== --&gt;
  &lt;!--  Datasource config for Postgres                                      --&gt;
  &lt;!-- ==================================================================== --&gt;
  
  
  &lt;datasources&gt;
      &lt;local-tx-datasource&gt;
          &lt;jndi-name&gt;pacsDS&lt;/jndi-name&gt;
          &lt;connection-url&gt;jdbc:postgresql://localhost/pacsdb&lt;/connection-url&gt;
          &lt;driver-class&gt;org.postgresql.Driver&lt;/driver-class&gt;
          &lt;user-name&gt;postgres&lt;/user-name&gt;
          &lt;password&gt;&lt;/password&gt;
          &lt;!-- sql to call when connection is created.  Can be anything, select 1 is valid for PostgreSQL
          &lt;new-connection-sql&gt;select 1&lt;/new-connection-sql&gt;
          --&gt;
  
          &lt;!-- sql to call on an existing pooled connection when it is obtained from pool.  Can be anything, select 1 is valid for PostgreSQL
          &lt;check-valid-connection-sql&gt;select 1&lt;/check-valid-connection-sql&gt;
          --&gt;
  
          &lt;!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) --&gt;
          &lt;metadata&gt;
              &lt;type-mapping&gt;PostgreSQL 7.2&lt;/type-mapping&gt;
          &lt;/metadata&gt;
      &lt;/local-tx-datasource&gt;
  &lt;/datasources&gt;
  </code></pre>