I don't believe that there's any way to change the connection url via the Datasource - this will only allow you to create connections from the preconfigured connection pool.

If you have multiple databases you can create multiple connection pools and bind them as seperate datasources (e.g. java:/jdbc/database1, java:/jdbc/database2) and look up the appropriate datasource from JNDI.

If you really need to dynamically change the connectionURL at runtime this can be done using JMX to call the Connection Manager MBean.

In JBoss 3.2.x there are 3 MBeans - the ConnectionManager, the ManagedConnectionPool and the ConnectionFactory. If you know the ObjectName of the ConnectionManager you can do something like this:

String newUrl = "newJdbcConnectionUrl";
ObjectName connectionManager = new ObjectName("jboss.jca:service=NoTxPool,name=myDS");
ObjectName connectionPool = (ObjectName)getServer().getAttribute(connectionManager, "ManagedConnectionPool");
ObjectName connectionFactory = (ObjectName)getServer().getAttribute(connectionPool, "ManagedConnectionFactoryName");
// change ConnectionURL ManagedConnectionFactoryAttribute
getServer().invoke(connectionFactory, "setManagedConnectionFactoryAttribute",
new Object[] {"ConnectionURL", String.class, newUrl},
new String[] {String.class.getName(), Class.class.getName(), Object.class.getName()} );
// flush connection pool - new connections will be created with the new URL
getServer().invoke(connectionPool, "flush", new Object[] {}, new String[] {});


Where getServer() is returning a reference to the MBeanServer:
e.g.
MBeanServer getServer()
{
    // find first MBean server in current JVM
    MBeanServerFactory.findMBeanServer(null).get(0);
}

Hope that helps,

-Andrew

Maffeo Gaetano wrote:

Hi all,

After i call:
ds = (DataSource)ctx.lookup("java:/"+Misc.getDSname(this.getContextRoot()));


how can i change the connectionURL od the DataSource?


many thanks in advance for whom helps me


gaetano




------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to