users@glassfish.java.net

Re: changing JDBC resources programmatically

From: Sreenivas Munnangi <Sreenivas.Munnangi_at_Sun.COM>
Date: Fri, 14 Dec 2007 11:19:02 -0800

Glenn Holmer wrote:
> glassfish_at_javadesktop.org wrote:
>
>>> What's the least painless way to make that take
>>>
>> You mean the least painful way, right? ;)
>>
>
> Yes, pain is not an option :)
>
>
>> I think you are not changing the JNDI names of the resource. It's just that the
>> connection pool points to a different database now. If that's the case, restart
>> of the *application* (e.g. disabling the app followed by enabling it) should
>> work. I don't think you need to restart the server.
>>
>
> This is what I'm doing:
>
> asadmin delete-jdbc-resource \
> --user admin --passwordfile /root/passwd.gf \
> jdbc/slm3
> asadmin create-jdbc-resource \
> --user admin --passwordfile /root/passwd.gf \
> --connectionpoolid wms400 --description "Online Order Entry" \
> jdbc/slm3
>
> Is it the best way?
>

You don't have to delete the jdbc resource as long as it points to a
connection pool with same name. Based on your original email, I
understand that when the switch happens, the connection pool points to a
different database. If this assumption is correct then what you'd do is
delete the old connection pool (pointing to old database) and create a
new connection pool (pointing to new database) with the same name, for ex.

> asadmin delete-jdbc-connection-pool wms400 // on the old machine
>asadmin create-jdbc-connection-pool --datasourceclassname <classname>
[...] wms400 // on the new machine

Since the connection pool name which is used by the JDBC Resource is the
same, in this case 'wms400', the JDBC resource does not have to be
deleted and re-created, just restart the application as pointed by Kedar.

If before and after switch, the connection pool points to same database
then restarting application should be enough.

HTH.

thanks
sreeni