tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jack Lauman <jlau...@nwcascades.com>
Subject JNDI / web.xml question
Date Thu, 10 Feb 2005 00:53:13 GMT
I'm trying to clean up a few files that have JNDI data access.  I want 
to move the datasource name to the web.xml for easier maintenance and to 
avoid having to hardcode it into the app.

If I have a datasource in the context-param area of the web.xml file, 
how can it be called?

<context-param>
    <param-name>jdbcDataSource</param-name>
    <param-value>java:comp/env/jdbc/RestaurantDS</param-value>
</context-param>


pageContext.
getServletContext().getInitParameter("insert-context-param-name-here");

The above doesn't work here... does anyone know how this can be done?

Thanks,

Jack

....
private void initialize()
{
    try {
        Context ctx = null;
        DataSource ds = null;
        Connection conn = null;
        Result result = null;
        try {
            ctx = new InitialContext();
            ds = (DataSource)
                 ctx.lookup("java:comp/env/jdbc/RestaurantDS");
        } catch (Exception e) {
        System.out.println("DataSource context lookup failed: " + e);
    }
    try {
        conn = ds.getConnection();
        } catch (Exception e) {
        System.out.println("DataSource getConnection failed: " + e);
          e.printStackTrace();
    }




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message