javax.servlet.ServletException: Name java:comp is not bound in this Context

hi

i am trying to do database connection using JNDI lookup.The following is the code for that:

Connection con;

Statement st;

Context ctx = new InitialContext();

Context envCtx = (Context) ctx.lookup("java:comp/env");

DataSource ds = (DataSource)envCtx.lookup("jdbc/cust");

con = ds.getConnection();

st=con.createStatement();

ResultSet rs=st.executeQuery("select * from customer");

while(rs.next())

{

out.println(rs.getString("custName"));

}

but i am getting error ,

exception

javax.servlet.ServletException: Name java:comp is not bound in this Context

org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)

org.apache.jsp.database_jsp._jspService(org.apache.jsp.database_jsp:143)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

javax.naming.NameNotFoundException: Name java:comp is not bound in this Context

org.apache.naming.NamingContext.lookup(NamingContext.java:769)

org.apache.naming.NamingContext.lookup(NamingContext.java:152)

javax.naming.InitialContext.lookup(InitialContext.java:392)

org.apache.jsp.database_jsp._jspService(org.apache.jsp.database_jsp:114)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

can anybody please tell me what went wrong?

regads

shruthi

[2283 byte] By [patel123a] at [2007-11-27 5:20:15]
# 1

You did not give much information about your container setup, but make sure you have the context name correct. Basically, 'java:comp' does not exist. Your container might be creating 'java:/comp' . You do have a context because you did not recieve an InitialContextException. So, you just need to get the name correct. Check you container docs.

brucehitchcocka at 2007-7-12 11:44:18 > top of Java-index,Core,Core APIs...