?
Solved

Tomcat Datasource

Posted on 2014-03-04
12
Medium Priority
?
319 Views
Last Modified: 2014-06-11
Hi  - I need to refer properties file in context.xml. For each environment I have different database names and need to tell to java app to use environment specific properties.

I configured  context.xml for each environment and every thing is working great.
ex: dev.xygpool
qat.xygpool
prd.xyzpool

The problem I am having is I have datasource name lmn and I need to configure the same name for prod and qat in context.xml. This is where I am having issues.

Can any one suggest best approach to configure datasource for each environment(dev,int,qat,prd)

All other property files I have are in environment specific folder and I am able to read all of the properties.

ex:
dev/xyz.properties
qat/xyg.properties
prd/xyz.properties

Any suggestions are welcome

Can we change userid and password and url dynamically in context.xml?
0
Comment
Question by:nzdjava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
12 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 39905932
easier will be to make two datasources and configure datasource name per-deployment/context and not use it directly by jsp-s
0
 
LVL 16

Accepted Solution

by:
Valeri earned 2000 total points
ID: 39908583
You have to have different server.xml's for each environment, in this way your context.xml should not be changed.

try this suggested by Maurice:
I put all my datasource definitions in the conf/server.xml file of tomcat, so the war is completely independent of the datasource.

in server.xml
-------------------------------------
<GlobalNamingResources>
    <Resource name="mail/Mail" auth="Container" type="javax.mail.Session"
              mail.smtp.host="localhost"/>
    <Resource auth="Container" type="javax.sql.DataSource" name="jdbc/lagalerie"
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://localhost/lagalerie?charSet=LATIN1"
              maxActive="100" maxIdle="30" maxWait="10000"
              username="casashop" password="casashop"/>
</GlobalNamingResources>
-------------------------------------

in context.xml
-------------------------------------
<ResourceLink global="jdbc/lagalerie" name="jdbc/lagalerie" type="javax.sql.DataSource"/>
  <ResourceLink global="mail/Mail" name="mail/Mail" type="javax.mail.Session"/>
-------------------------------------

in web.xml
-------------------------------------
<resource-ref>
    <description>The datasource</description>
    <res-ref-name>jdbc/DataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
    <description>The mail session</description>
    <res-ref-name>mail/Mail</res-ref-name>
    <res-type>javax.mail.Session</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
-------------------------------------
0
 

Author Comment

by:nzdjava
ID: 39941622
I've requested that this question be deleted for the following reason:

Didnt get correct way of approaching this
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 2000 total points
ID: 39941623
Did you try my solution?
You have to change properly only the server.xml's on each one of the environments. Nothing more is needed.
0
 
LVL 62

Expert Comment

by:gheist
ID: 39941636
My first answer outlines similar idea too ;)
0
 

Author Comment

by:nzdjava
ID: 39962844
Valleri - I cant modify server.xml in each environment. All we can do is package and deploy it in tomcat. It should be in our package. Let me know if I can do that.

Thanks for your help.

Thanks
0
 

Author Comment

by:nzdjava
ID: 40128318
I've requested that this question be deleted for the following reason:

No t able to get the correct answers for this question
0
 
LVL 62

Expert Comment

by:gheist
ID: 40128314
Sorry but months after it is completely wrong to pull out of the question mentioning some nonsense.
Tomcat provides JDBC connection pools, so the best place to define datasources is server.xml
That becomes especially critical when DBA wants to change database driver before or after DB upgrade and some even older drivers are planted in each web application.

Here you have http:#a39941623 correct answer to your question.
Ok it does not say it is bad to encapsulate driver in your webapp etc, but if you asked on how to plant it in webapp you would get exactly pointed to use app servers facilities...
0
 
LVL 62

Expert Comment

by:gheist
ID: 40128634
Well yes, and it even includes cut from file to be changed.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question