Posted By:
Judith_Spengeman
Posted On:
Wednesday, September 29, 2004 10:51 AM
I have written a ServletContextListener which schedules a TimerTask. The task then accesses a database to populate a collection of system messages and repopulates the messages every 30 minutes. I would like to use the application servers environment to perform the JNDI lookup to get the DataSource object for the database. I get a no namespace error when using "DataSource dSource = (DataSource)((new InitialContext()).lookup("java:comp/env/jdbc/dataSource"));" Where "jdbc/dataSource" is defined in my web.xml. Everthing works fine when I use "DataSource dSource = (DataSource)((new InitialContext()).lookup("jdbc/dataSource"));"
More>>
I have written a ServletContextListener which schedules a TimerTask. The task then accesses a database to populate a collection of system messages and repopulates the messages every 30 minutes.
I would like to use the application servers environment to perform the JNDI lookup to get the DataSource object for the database.
I get a no namespace error when using "DataSource dSource = (DataSource)((new InitialContext()).lookup("java:comp/env/jdbc/dataSource"));" Where "jdbc/dataSource" is defined in my web.xml.
Everthing works fine when I use "DataSource dSource = (DataSource)((new InitialContext()).lookup("jdbc/dataSource"));"
Any suggestions on how to use the resource-ref tags in my web.xml to keep my code portable, even though the TimerTask appears to be executing in a thread outside of my web application?
Thanks!
<<Less