Forums Register Login

ServeltContextListener for DataSource

+Pie Number of slices to send: Send
While discussing about ServletContextListener, HFSJSP 2e says that it is used for initializing a DataSource. Is this a good approach? I've seen the DataSource objects are handled by the container itself. What is the best way?
+Pie Number of slices to send: Send
Any suggestions?
+Pie Number of slices to send: Send
My take on this is that it's a good way to do it because the datasource lookup only happens once. I've seen other code where the lookup happens over and over again which is a waste of resources. I've tried different ways of doing it and based on feedback that I received here, this is the context listener that I now use.



This is the DataSourceHolder class:

Suggestions for improving this are welcome.
+Pie Number of slices to send: Send
If you're using Java EE 6, there are many good ways, one of the good ways is contextInitialized, the easiest good way is @Resource.
+Pie Number of slices to send: Send
is there also possible to initialize DataSource in context.xml file?
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2131 times.
Similar Threads
servlets and xml
what kind of object can be bound to JNDI?
What sort of connectivity does JDBC provides.
JDBC - As/400 CCSID = 65535 problem
Question about ejbActivate and ejbPassivate
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 21:35:54.