tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gregor Schneider <rc4...@googlemail.com>
Subject Re: Is it possible to connect to a different database based on the URL?
Date Tue, 20 Apr 2010 13:58:13 GMT
On Tue, Apr 20, 2010 at 3:00 PM, Shinan Kassam <shinank@gmail.com> wrote:
>
> I currently have custom authentication working using JDBCRealm. Hence, I
> have some database parameters in server.xml as well as my application. Is it
> possible to use a portion of the URL as a parameter to connect to a
> different database.
>

shot from the hip:

- specify all databases available inside your context.xml-file

- from the url, read a parameter (such as "&customer=scrooge")

- depending on the parameter, create the datasource:


			try {
				Context env = (Context) new InitialContext().lookup("java:comp/env");
				dbDS = (DataSource) env.lookup(customer);
				if (dbDS == null) {
					logger.error("seems that '" + dataSourceName + "' is an unknown
DataSource");
					throw new ServletException("'" + dataSourceName + "' is an
unknown DataSource");
				}
			} catch (NamingException e) {
				logger.error("Exception caught:", e);
				throw new ServletException(e);
			}

hth

gregor
-- 
just because you're paranoid, don't mean they're not after you...
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available
@ http://pgpkeys.pca.dfn.de:11371
@ http://pgp.mit.edu:11371/
skype:rc46fi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message