Two Laptop Bag*
The moose likes Servlets and the fly likes JDBC Parameters as Context Parameters? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JDBC Parameters as Context Parameters?" Watch "JDBC Parameters as Context Parameters?" New topic

JDBC Parameters as Context Parameters?

Jenn Person
Ranch Hand

Joined: Jan 16, 2005
Posts: 89
I have my JDBC parameters set as context parameters in my web.xml file as such:

Is this ok to do? Or a bad idea? I know it works, and did it primarily so I could maintain these attributes through just the web.xml file.
[ March 29, 2007: Message edited by: Jenn Person ]
Sunil Vasudevan
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
It is OK to do what you are doing.

But a better approach is to let your Web/App server handle database connections. They handle it in a more efficient manner.

Which web/app server are you using?
[ March 30, 2007: Message edited by: Sunil Vasudevan ]

Sunil.V<br />SCJP2, SCWCD1.4, SCBCD1.3
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Why do not you use the connection pool provided by the container as Sunil mentioned? Or , if you want to go by this approach then it would be bettter to have a file within your application , which would have all the connection related parameters.

Rahul Bhattacharjee
LinkedIn - Blog
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
If it is for learning to use context parameters then it is fine..

But for an application in production environment ,it is better to go by what the others mentioned in the above posts...
Deepan Devadasan
Ranch Hand

Joined: Jan 25, 2007
Posts: 226
Hi Folks...

I am curious to learn things, what you mentioned as 'other' methods...

How does Container/Server Managed DB connections or connection pooling work...

Please advice me on the above

Theepan Thevathasan
SCJP 1.4, SCWCD 1.4, SCMAD 1.0 SCBCD 1.3, MCP(.Net Frm 2.0 App Dev Fdn)
Jenn Person
Ranch Hand

Joined: Jan 16, 2005
Posts: 89
I've never used, or been aware of , a connection pool. I'll have to look into that.

Otherwise, besides less efficiency, are there any other setbacks to making them context parameters in terms of security perhaps?
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I do not see and security threat to your approach as this (web.xml) would be within the WEB-INF directory.In fact I have worked on some application where some parameters are passed to the application using the init-param.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: JDBC Parameters as Context Parameters?
Similar Threads
implicit object doubt
config my-faces & tomahawk & Trinidad
Missing application web.xml, using defaults only
javax. servlet. ServletException: Name myoracle is not bound in this Context
Doubt in ServletContextListener