Thanks Raymond, exactly what I needed!
Frederik
"STOCKHOLM, Raymond" <[EMAIL PROTECTED]> wrote:
Use tomcat's pooling mecanism :
in $TOMCAT/conf/server.xml, in your application Context, declare a Resource :
pathname="">
factory
org.apache.commons.dbcp.BasicDataSourceFactory
maxActive
100
maxIdle
30000
maxWait
100
username
sa
password
sa
driverClassName
com.microsoft.jdbc.sqlserver.SQLServerDriver(your driver)
url
your.url.with.correct.driver
validationQuery
select getdate()
You can, in your servlet, access the datasource :
try {
Context ctx = new InitialContext();
this.dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/YOUR_DATABASE");
} catch (NamingException e) {
log.error("Constructor throws NamingException " + e.getMessage());
}
And then get a connection from it :
Connection conn = dataSource.getConnection();
-----Message d'origine-----
De : frederik gens [mailto:[EMAIL PROTECTED]
Envoy� : vendredi 18 juin 2004 11:20
� : [EMAIL PROTECTED]
Objet : NEWBIE: flexible declaration of a database URL
Hello,
I'm currently developing a JSP/Servlet/JDBC application with Tomcat. In several
classes called by servlets, I declare the URL which identify the database in order to
open the connection.
My question is: what is the best way to declare this URL only once, for example in a
file, or in an environment variable. Therefore, the classes always call this variable.
Changing the place of the database just requires to change the URL in one place.
Thanks in advance!
Frederik
---------------------------------
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!