error with JNDI & Tomcat 5


General J2EE: error with JNDI & Tomcat 5

  1. error with JNDI & Tomcat 5 (1 messages)

    i am new to DataSource and Connection Pool,
    i am trying to get a connection pool from the datasource i follwoed the instructions posted on jakarta web site:
     but i am getting error:
    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

    i am sure my java code:
    InitialContext ctx = new InitialContext();
                  if(ctx == null )
                  System.out.println(" no context");
                  System.out.println(" good context");
                  DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
                  if (ds != null) {
                    conn = ds.getConnection();
            } catch (NamingException ex) {
            }catch (SQLException e) {
    my web.xml :
          <description>DB Connection</description>

    but i am not sure if i have to add an <environment> tag to the server.xml (See the link above) if i do plz show me an example .
    if any body has experience with this problem plz help me.

    here's my setup:

        <Resource name="jdbc/foo" type="javax.sql.DataSource"/>
        <ResourceParams name="jdbc/foo">
    ... [other db connection info]

    datasource jndi name (I use hibernate, so can't help you with the context):