You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Philippe Mathieu <ph...@lifl.fr> on 2005/01/26 08:36:58 UTC
the default name of the local data source
I am using Tomcat 5.0.28 and my WAR uses a ConnectionPool defined in the
application context (localDataSource).
To access it, the doc says that we must use these 3 lines in JSP's.
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("mypool");
Connection con = ds.getConnection();
The disaventage is that if there are many WAR with the same
localDataSource name, i will have to edit all the JSP/Beans to change
the localDataSourceNames.
Is there any way to avoid saying the ressource name and for example
telling that i want to use the localDataSource (without its name) ?
--
Phil
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: the default name of the local data source
Posted by Parsons Technical Services <pa...@earthlink.net>.
I know there is a way to read in the name but am unsure how to do it at this
point. But there is a logistic issue with it. What if there is more than
one?
You could do one of three things.
Either:
On startup read in the ds and store it. Then have each class simple grab the
ds each time.
Or:
Use a properties file to store the name. It is read in during startup and
stored. Each envCtx.lookup will then use the static variable in place of the
name.
Or:
On startup create a static class to hold data. Have the variable initialized
to the name. Then all classes ref this variable.
It depends on if you want to change it without editing the war.
Doug
----- Original Message -----
From: "Philippe Mathieu" <ph...@lifl.fr>
To: <to...@jakarta.apache.org>
Sent: Wednesday, January 26, 2005 2:36 AM
Subject: the default name of the local data source
>I am using Tomcat 5.0.28 and my WAR uses a ConnectionPool defined in the
>application context (localDataSource).
>
> To access it, the doc says that we must use these 3 lines in JSP's.
> Context initCtx = new InitialContext();
> Context envCtx = (Context) initCtx.lookup("java:comp/env");
> DataSource ds = (DataSource) envCtx.lookup("mypool");
> Connection con = ds.getConnection();
>
> The disaventage is that if there are many WAR with the same
> localDataSource name, i will have to edit all the JSP/Beans to change the
> localDataSourceNames.
>
> Is there any way to avoid saying the ressource name and for example
> telling that i want to use the localDataSource (without its name) ?
>
> --
> Phil
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org