Hi João, This documentation also says:
When the attribute factory="org.apache.naming.factory.DataSourceLinkFactory"the resource link can be used with two additional attributes to allow a shared data source to be used with different credentials. When these two additional attributes are used in combination with the javax.sql.DataSourcetype, different contexts can share a global data source with different credentials. Under the hood, what happens is that a call to getConnection()<http://download.oracle.com/javase/6/docs/api/javax/sql/DataSource.html#getConnection%28%29>is simply translated to a call getConnection(username, password)<http://download.oracle.com/javase/6/docs/api/javax/sql/DataSource.html#getConnection%28java.lang.String,%20java.lang.String%29>on the global data source. This is an easy way to get code to be transparent to what schemas are being used, yet be able to control connections (or pools) in the global configuration. AttributeDescriptionusername username value for the getConnection(username, password) call on the linked global DataSource. password password value for the getConnection(username, password) call on the linked global DataSource. Thanks, Robert On Wed, May 23, 2012 at 6:26 PM, Joao Silva <joao.si...@vilt-group.com>wrote: > Hi > > The ResourceLink element will use the parameters name, global and type. > Everything else is being ignored, as the resource link is but reference to > the global shared data source. > See http://tomcat.apache.org/tomcat-7.0-doc/config/context.html, > searching for ResourceLink. > > Best regards > > > On 5/23/2012 9:31 PM, Robert Anderson wrote: > > Hi, > > I'm testing this functionality (versions 6.0.35 and 7.0.27) but it's not > working for me (https://issues.apache.org/bugzilla/show_bug.cgi?id=49543 > ,http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Links). > > > -->server.xml > > > <GlobalNamingResources> > > <Resource name="jdbc/globalpg" auth="Container" > type="javax.sql.DataSource" removeAbandoned="true" > removeAbandonedTimeout="300" > maxActive="400" maxIdle="30" > maxWait="10000" > validationQuery="select 1" > testOnBorrow="true" > > factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" > driverClassName="org.postgresql.Driver" > > url="jdbc:postgresql://172.17.1.5:5432/tjse" > username="user1" > password="validpassword" > /> > > </GlobalNamingResources> > > > -->conf/Catalina/localhost/app1.xml > > > <Context> > > <ResourceLink name="jdbc/localpg" > global="jdbc/globalpg" > type="javax.sql.DataSource" > factory="org.apache.naming.factory.DataSourceLinkFactory" > username="user2" > password="invalidpassword" > /> > > </Context> > > > -->webapps/app1/index.jsp > > <?xml version="1.0" encoding="ISO-8859-1"?> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > <http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>> > <%@ page session="false" import="javax.naming.*, java.sql.*, javax.sql.*" %> > <html xmlns="http://www.w3.org/1999/xhtml" <http://www.w3.org/1999/xhtml> > xml:lang="en" lang="en"> > <head> > <title>Test shared data source</title> > </head> > <body> > <% > Context ctx = new InitialContext(); > DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/localpg"); > Connection c = ds.getConnection(); > Statement stm = c.createStatement(); > > ResultSet rs = stm.executeQuery("select 'this should fail because the > password of localpg is invalid but it is working.'"); > > rs.next(); > > %> > <%= rs.getString(1) %><br/> > <% > > c.close(); > %> > </body> > </html> > > > Am I doing some wrong? > > > Thanks in advance, > > > Robert > > > > -- > *João Silva > * * > VILT Group > * *http://www.vilt-group.com > > Rua Ivone Silva, 6 - 7º Esq > 1050-124 Lisboa - Portugal > > Mobile +351 926 531 097 > Phone +351 210 34 33 00 > Fax +351 210 34 33 99 > Email joao.si...@vilt-group.com* >