Topic
  • 30 replies
  • Latest Post - ‏2010-09-15T03:08:55Z by Jeuz
SystemAdmin
SystemAdmin
1215 Posts

Pinned topic javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

‏2004-07-07T07:56:15Z |
Hi,
I'm using Websphere Studio Enterprise Developer.

I get the following error:
javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:"

This is my code:

<%@page import="javax.naming., java.sql., javax.sql.*"%>
<% Connection conn;

java.util.Properties parms = new java.util.Properties();
parms.setProperty (Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");

Context ctx = new InitialContext(parms);

DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/OracleSample");

conn = ds.getConnection("dw", "dw");

%>

Any idea, please?

Davinia.
Updated on 2010-09-15T03:08:55Z at 2010-09-15T03:08:55Z by Jeuz
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2004-07-07T18:53:32Z  
    try posting your code again and i can probably help you
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2004-07-19T08:12:53Z  
    try posting your code again and i can probably help you
    I face the same problem :
    javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:"

    The source :
    public Connection getConnection()
    throws ClassNotFoundException, SQLException, Exception {
    Connection conn = null;
    try {
    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/WBSRC");
    conn = ds.getConnection();
    conn.setAutoCommit(false);
    } catch (SQLException e) {
    e.printStackTrace();
    throw e;
    } catch (Exception ne) {
    ne.printStackTrace();
    throw ne;
    }
    return conn;
    }
    I am using Websphere 5.1 on Windows 2000 and Unix.

    I have created a Datasource with the name : jdbc/WBSRC

    I have not specified anything related to jdbc/WBSRC in web.xml
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2004-09-07T14:54:27Z  
    > Hi,
    > I'm using Websphere Studio Enterprise Developer.
    >
    > I get the following error:
    > javax.naming.NameNotFoundException: Name
    > comp/env/jdbc not found in context "java:"
    >
    > This is my code:
    >
    > <%@page import="javax.naming., java.sql.,
    > javax.sql.*"%>
    > <% Connection conn;
    >
    > java.util.Properties parms = new
    > java.util.Properties();
    > parms.setProperty (Context.INITIAL_CONTEXT_FACTORY,
    > "com.ibm.websphere.naming.WsnInitialContextFactory");
    >
    > Context ctx = new InitialContext(parms);
    >
    > DataSource ds =
    > (DataSource)ctx.lookup("java:comp/env/jdbc/OracleSampl
    > ");
    >
    > conn = ds.getConnection("dw", "dw");
    >
    > %>
    >
    > Any idea, please?
    >
    > Davinia.

    Hi,

    I had a similar problem. Try this. Set up a datasource alias and refer to it as follows.

    Open "Web.xml" in your project and from the "References" tab select the "Resources" tab.

    Add a new resource and name it whatever you like e.g "ds1". Then type in the jndi name exactly as configured in your datasource e.g "jdbc/ds1"

    Then change your code to refer to the alias "ds1":

    DataSource ds =
    (DataSource)ctx.lookup("java:comp/env/jdbc/ds1");

    Hope this helps.
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2004-10-15T17:05:57Z  
    > Hi,
    > I'm using Websphere Studio Enterprise Developer.
    >
    > I get the following error:
    > javax.naming.NameNotFoundException: Name
    > comp/env/jdbc not found in context "java:"
    >
    > This is my code:
    >
    > <%@page import="javax.naming., java.sql.,
    > javax.sql.*"%>
    > <% Connection conn;
    >
    > java.util.Properties parms = new
    > java.util.Properties();
    > parms.setProperty (Context.INITIAL_CONTEXT_FACTORY,
    > "com.ibm.websphere.naming.WsnInitialContextFactory");
    >
    > Context ctx = new InitialContext(parms);
    >
    > DataSource ds =
    > (DataSource)ctx.lookup("java:comp/env/jdbc/OracleSampl
    > ");
    >
    > conn = ds.getConnection("dw", "dw");
    >
    > %>
    >
    > Any idea, please?
    >
    > Davinia.

    Hi,

    I had a similar problem. Try this. Set up a datasource alias and refer to it as follows.

    Open "Web.xml" in your project and from the "References" tab select the "Resources" tab.

    Add a new resource and name it whatever you like e.g "ds1". Then type in the jndi name exactly as configured in your datasource e.g "jdbc/ds1"

    Then change your code to refer to the alias "ds1":

    DataSource ds =
    (DataSource)ctx.lookup("java:comp/env/jdbc/ds1");

    Hope this helps.
    Check your ibm-web-bnd.xmi It should have binding information for the jndi name like

    resRefBindings xmi:id="ResourceRefBinding_xxxxxxx" jndiName="jdbc/testDataSource"

    You can add it using IDE by editing web.xml
    Refrences --> Resource and selecting the Resource Refrence in this case it was e.g jdbc/testDataSource.
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2004-12-17T18:10:27Z  
    Check your ibm-web-bnd.xmi It should have binding information for the jndi name like

    resRefBindings xmi:id="ResourceRefBinding_xxxxxxx" jndiName="jdbc/testDataSource"

    You can add it using IDE by editing web.xml
    Refrences --> Resource and selecting the Resource Refrence in this case it was e.g jdbc/testDataSource.
    Hi,
    I have the same problem , but slightly different from the above said ones. I have an application which runs many threads and is loaded from a servlet. I have a Datasource configured and have a resource reference defined for the purpose.

    I am able to get the reference to this Datasource through Resource reference when called directly from the servlet's thread. But if one of the other threads (application threads) tries to access the Datasource I get the exception " javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:" ". I have a utility class which returns the datasource and I get exception when the same is called from a different thread other than the main servlet thread. This is true only for Resource reference lookups (in my case java:comp/env/jdbc/sample). I am able to get the reference , both from servlet thread and the other threads ,if i directly use the jndi binding (in my case it is jdbc/sample). I am confused about how to proceed , I can get away by directly using the acutal JNDI name and not Resource Reference, but I get some messages in log when i do that and I have read somewhere that it happens when you dont access the resource through a resource reference.

    Could this be a bug with Websphere or I am missing some important detail of configuring. I tried this on both the Test Environment and Base version with Deployment Manger. Attaching is the Servlet I used for testing.

    Source

    import java.io.IOException;
    import javax.naming.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.sql.DataSource;
    import com.test.TestContext;

    class MyThread extends Thread{
    public void run() {
    try {
    InitialContext context = new InitialContext();
    DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/avs1sun");
    System.out.println("Datasource = " + ds);
    }catch (Exception e ){
    e.printStackTrace();
    }
    }
    }

    public class TestServlet extends HttpServlet implements Servlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    MyThread t = new MyThread();
    System.out.println("Running using Servlet's main Thread");
    t.run();
    System.out.println("Now running using a new Thread");
    t.start();
    }
    }
    Result


    12/17/04 23:32:14:219 IST 3c9bcae3 WsServer A WSVR0001I: Server server1 open for e-business
    12/17/04 23:32:17:547 IST 68d08ae1 WebGroup I SRVE0180I: AVSCoreAppWeb [/AVSCoreAppWeb] http://Servlet.LOG: TestServlet: init
    12/17/04 23:32:17:562 IST 68d08ae1 SystemOut O Running using Servlet's main Thread
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Datasource = com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource@4835caed
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Now running using a new Thread
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1663)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1009)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:932)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1261)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:194)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:135)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at javax.naming.InitialContext.lookup(InitialContext.java:360)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at MyThread.run(TestServlet.java:17)
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2004-12-21T19:02:15Z  
    Hi,
    I have the same problem , but slightly different from the above said ones. I have an application which runs many threads and is loaded from a servlet. I have a Datasource configured and have a resource reference defined for the purpose.

    I am able to get the reference to this Datasource through Resource reference when called directly from the servlet's thread. But if one of the other threads (application threads) tries to access the Datasource I get the exception " javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:" ". I have a utility class which returns the datasource and I get exception when the same is called from a different thread other than the main servlet thread. This is true only for Resource reference lookups (in my case java:comp/env/jdbc/sample). I am able to get the reference , both from servlet thread and the other threads ,if i directly use the jndi binding (in my case it is jdbc/sample). I am confused about how to proceed , I can get away by directly using the acutal JNDI name and not Resource Reference, but I get some messages in log when i do that and I have read somewhere that it happens when you dont access the resource through a resource reference.

    Could this be a bug with Websphere or I am missing some important detail of configuring. I tried this on both the Test Environment and Base version with Deployment Manger. Attaching is the Servlet I used for testing.

    Source

    import java.io.IOException;
    import javax.naming.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.sql.DataSource;
    import com.test.TestContext;

    class MyThread extends Thread{
    public void run() {
    try {
    InitialContext context = new InitialContext();
    DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/avs1sun");
    System.out.println("Datasource = " + ds);
    }catch (Exception e ){
    e.printStackTrace();
    }
    }
    }

    public class TestServlet extends HttpServlet implements Servlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    MyThread t = new MyThread();
    System.out.println("Running using Servlet's main Thread");
    t.run();
    System.out.println("Now running using a new Thread");
    t.start();
    }
    }
    Result


    12/17/04 23:32:14:219 IST 3c9bcae3 WsServer A WSVR0001I: Server server1 open for e-business
    12/17/04 23:32:17:547 IST 68d08ae1 WebGroup I SRVE0180I: AVSCoreAppWeb [/AVSCoreAppWeb] http://Servlet.LOG: TestServlet: init
    12/17/04 23:32:17:562 IST 68d08ae1 SystemOut O Running using Servlet's main Thread
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Datasource = com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource@4835caed
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Now running using a new Thread
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1663)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1009)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:932)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1261)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:194)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:135)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at javax.naming.InitialContext.lookup(InitialContext.java:360)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at MyThread.run(TestServlet.java:17)
    It seems as though user defined threads do not get a copy of the JNDI context. I suggest either using async beans

    http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/ae/rdat_isolevtab.html

    or looking up the datasource in the main thread and saving it off to use in the user defined threads.

    Good luck!
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2004-12-21T19:05:28Z  
    It seems as though user defined threads do not get a copy of the JNDI context. I suggest either using async beans

    http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/ae/rdat_isolevtab.html

    or looking up the datasource in the main thread and saving it off to use in the user defined threads.

    Good luck!
    Sorry, the above link was messed up. Try:

    http://publib.boulder.ibm.com/infocenter/wasinfo/topic/com.ibm.wasee.doc/info/ee/asyncbns/tasks/tasb_epasb.html
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2005-01-13T15:04:09Z  
    I face the same problem :
    javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:"

    The source :
    public Connection getConnection()
    throws ClassNotFoundException, SQLException, Exception {
    Connection conn = null;
    try {
    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/WBSRC");
    conn = ds.getConnection();
    conn.setAutoCommit(false);
    } catch (SQLException e) {
    e.printStackTrace();
    throw e;
    } catch (Exception ne) {
    ne.printStackTrace();
    throw ne;
    }
    return conn;
    }
    I am using Websphere 5.1 on Windows 2000 and Unix.

    I have created a Datasource with the name : jdbc/WBSRC

    I have not specified anything related to jdbc/WBSRC in web.xml
    how did you fix?

    "deepakgm1" <deepakgm@hotmail.com> wrote in message
    news:638351985.1090224773993.JavaMail.wasadmin@swg3ws003...
    > I face the same problem :
    > javax.naming.NameNotFoundException: Name comp/env/jdbc not found in
    context "java:"
    >
    > The source :
    > public Connection getConnection()
    > throws ClassNotFoundException, SQLException, Exception {
    > Connection conn = null;
    > try {
    > InitialContext ctx = new InitialContext();
    > DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/WBSRC");
    > conn = ds.getConnection();
    > conn.setAutoCommit(false);
    > } catch (SQLException e) {
    > e.printStackTrace();
    > throw e;
    > } catch (Exception ne) {
    > ne.printStackTrace();
    > throw ne;
    > }
    > return conn;
    > }
    >
    >
    > I am using Websphere 5.1 on Windows 2000 and Unix.
    >
    > I have created a Datasource with the name : jdbc/WBSRC
    >
    > I have not specified anything related to jdbc/WBSRC in web.xml
    >
    >

  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2005-03-22T07:05:18Z  
    I face the same problem :
    javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:"

    The source :
    public Connection getConnection()
    throws ClassNotFoundException, SQLException, Exception {
    Connection conn = null;
    try {
    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/WBSRC");
    conn = ds.getConnection();
    conn.setAutoCommit(false);
    } catch (SQLException e) {
    e.printStackTrace();
    throw e;
    } catch (Exception ne) {
    ne.printStackTrace();
    throw ne;
    }
    return conn;
    }
    I am using Websphere 5.1 on Windows 2000 and Unix.

    I have created a Datasource with the name : jdbc/WBSRC

    I have not specified anything related to jdbc/WBSRC in web.xml
    i am also using WSAD 5.1.2 still facing the same problem .did u solve this, if yes pls help me
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2005-07-07T02:20:14Z  
    Hi,
    I have the same problem , but slightly different from the above said ones. I have an application which runs many threads and is loaded from a servlet. I have a Datasource configured and have a resource reference defined for the purpose.

    I am able to get the reference to this Datasource through Resource reference when called directly from the servlet's thread. But if one of the other threads (application threads) tries to access the Datasource I get the exception " javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:" ". I have a utility class which returns the datasource and I get exception when the same is called from a different thread other than the main servlet thread. This is true only for Resource reference lookups (in my case java:comp/env/jdbc/sample). I am able to get the reference , both from servlet thread and the other threads ,if i directly use the jndi binding (in my case it is jdbc/sample). I am confused about how to proceed , I can get away by directly using the acutal JNDI name and not Resource Reference, but I get some messages in log when i do that and I have read somewhere that it happens when you dont access the resource through a resource reference.

    Could this be a bug with Websphere or I am missing some important detail of configuring. I tried this on both the Test Environment and Base version with Deployment Manger. Attaching is the Servlet I used for testing.

    Source

    import java.io.IOException;
    import javax.naming.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.sql.DataSource;
    import com.test.TestContext;

    class MyThread extends Thread{
    public void run() {
    try {
    InitialContext context = new InitialContext();
    DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/avs1sun");
    System.out.println("Datasource = " + ds);
    }catch (Exception e ){
    e.printStackTrace();
    }
    }
    }

    public class TestServlet extends HttpServlet implements Servlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    MyThread t = new MyThread();
    System.out.println("Running using Servlet's main Thread");
    t.run();
    System.out.println("Now running using a new Thread");
    t.start();
    }
    }
    Result


    12/17/04 23:32:14:219 IST 3c9bcae3 WsServer A WSVR0001I: Server server1 open for e-business
    12/17/04 23:32:17:547 IST 68d08ae1 WebGroup I SRVE0180I: AVSCoreAppWeb [/AVSCoreAppWeb] http://Servlet.LOG: TestServlet: init
    12/17/04 23:32:17:562 IST 68d08ae1 SystemOut O Running using Servlet's main Thread
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Datasource = com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource@4835caed
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Now running using a new Thread
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1663)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1009)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:932)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1261)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:194)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:135)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at javax.naming.InitialContext.lookup(InitialContext.java:360)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at MyThread.run(TestServlet.java:17)
    I have the same problem with you. Can you tell me how you solve it? My email address is hecz@itpub.net
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2005-07-07T03:23:33Z  
    Hi,
    I have the same problem , but slightly different from the above said ones. I have an application which runs many threads and is loaded from a servlet. I have a Datasource configured and have a resource reference defined for the purpose.

    I am able to get the reference to this Datasource through Resource reference when called directly from the servlet's thread. But if one of the other threads (application threads) tries to access the Datasource I get the exception " javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:" ". I have a utility class which returns the datasource and I get exception when the same is called from a different thread other than the main servlet thread. This is true only for Resource reference lookups (in my case java:comp/env/jdbc/sample). I am able to get the reference , both from servlet thread and the other threads ,if i directly use the jndi binding (in my case it is jdbc/sample). I am confused about how to proceed , I can get away by directly using the acutal JNDI name and not Resource Reference, but I get some messages in log when i do that and I have read somewhere that it happens when you dont access the resource through a resource reference.

    Could this be a bug with Websphere or I am missing some important detail of configuring. I tried this on both the Test Environment and Base version with Deployment Manger. Attaching is the Servlet I used for testing.

    Source

    import java.io.IOException;
    import javax.naming.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.sql.DataSource;
    import com.test.TestContext;

    class MyThread extends Thread{
    public void run() {
    try {
    InitialContext context = new InitialContext();
    DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/avs1sun");
    System.out.println("Datasource = " + ds);
    }catch (Exception e ){
    e.printStackTrace();
    }
    }
    }

    public class TestServlet extends HttpServlet implements Servlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    MyThread t = new MyThread();
    System.out.println("Running using Servlet's main Thread");
    t.run();
    System.out.println("Now running using a new Thread");
    t.start();
    }
    }
    Result


    12/17/04 23:32:14:219 IST 3c9bcae3 WsServer A WSVR0001I: Server server1 open for e-business
    12/17/04 23:32:17:547 IST 68d08ae1 WebGroup I SRVE0180I: AVSCoreAppWeb [/AVSCoreAppWeb] http://Servlet.LOG: TestServlet: init
    12/17/04 23:32:17:562 IST 68d08ae1 SystemOut O Running using Servlet's main Thread
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Datasource = com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource@4835caed
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Now running using a new Thread
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1663)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1009)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:932)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1261)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:194)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:135)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at javax.naming.InitialContext.lookup(InitialContext.java:360)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at MyThread.run(TestServlet.java:17)
    I think the following two page can solve your problem!

    http://www-1.ibm.com/support/docview.wss?uid=swg21175742
    http://www-1.ibm.com/support/docview.wss?uid=swg21168795
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2005-10-19T18:36:12Z  
    Hi,
    I have the same problem , but slightly different from the above said ones. I have an application which runs many threads and is loaded from a servlet. I have a Datasource configured and have a resource reference defined for the purpose.

    I am able to get the reference to this Datasource through Resource reference when called directly from the servlet's thread. But if one of the other threads (application threads) tries to access the Datasource I get the exception " javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:" ". I have a utility class which returns the datasource and I get exception when the same is called from a different thread other than the main servlet thread. This is true only for Resource reference lookups (in my case java:comp/env/jdbc/sample). I am able to get the reference , both from servlet thread and the other threads ,if i directly use the jndi binding (in my case it is jdbc/sample). I am confused about how to proceed , I can get away by directly using the acutal JNDI name and not Resource Reference, but I get some messages in log when i do that and I have read somewhere that it happens when you dont access the resource through a resource reference.

    Could this be a bug with Websphere or I am missing some important detail of configuring. I tried this on both the Test Environment and Base version with Deployment Manger. Attaching is the Servlet I used for testing.

    Source

    import java.io.IOException;
    import javax.naming.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.sql.DataSource;
    import com.test.TestContext;

    class MyThread extends Thread{
    public void run() {
    try {
    InitialContext context = new InitialContext();
    DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/avs1sun");
    System.out.println("Datasource = " + ds);
    }catch (Exception e ){
    e.printStackTrace();
    }
    }
    }

    public class TestServlet extends HttpServlet implements Servlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    MyThread t = new MyThread();
    System.out.println("Running using Servlet's main Thread");
    t.run();
    System.out.println("Now running using a new Thread");
    t.start();
    }
    }
    Result


    12/17/04 23:32:14:219 IST 3c9bcae3 WsServer A WSVR0001I: Server server1 open for e-business
    12/17/04 23:32:17:547 IST 68d08ae1 WebGroup I SRVE0180I: AVSCoreAppWeb [/AVSCoreAppWeb] http://Servlet.LOG: TestServlet: init
    12/17/04 23:32:17:562 IST 68d08ae1 SystemOut O Running using Servlet's main Thread
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Datasource = com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource@4835caed
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Now running using a new Thread
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1663)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1009)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:932)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1261)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:194)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:135)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at javax.naming.InitialContext.lookup(InitialContext.java:360)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at MyThread.run(TestServlet.java:17)
    heii.. i got the same problem, now it is resolved.

    create an alia name for your jndi through web.xml and try again, it should work...

    if any problems further, mail me back srmselva@yahoo.com
  • Sreenivas_Tummala
    Sreenivas_Tummala
    1 Post

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2005-10-27T15:34:45Z  
    > Hi,
    > I'm using Websphere Studio Enterprise Developer.
    >
    > I get the following error:
    > javax.naming.NameNotFoundException: Name
    > comp/env/jdbc not found in context "java:"
    >
    > This is my code:
    >
    > <%@page import="javax.naming., java.sql.,
    > javax.sql.*"%>
    > <% Connection conn;
    >
    > java.util.Properties parms = new
    > java.util.Properties();
    > parms.setProperty (Context.INITIAL_CONTEXT_FACTORY,
    > "com.ibm.websphere.naming.WsnInitialContextFactory");
    >
    > Context ctx = new InitialContext(parms);
    >
    > DataSource ds =
    > (DataSource)ctx.lookup("java:comp/env/jdbc/OracleSampl
    > ");
    >
    > conn = ds.getConnection("dw", "dw");
    >
    > %>
    >
    > Any idea, please?
    >
    > Davinia.

    Hi,

    I had a similar problem. Try this. Set up a datasource alias and refer to it as follows.

    Open "Web.xml" in your project and from the "References" tab select the "Resources" tab.

    Add a new resource and name it whatever you like e.g "ds1". Then type in the jndi name exactly as configured in your datasource e.g "jdbc/ds1"

    Then change your code to refer to the alias "ds1":

    DataSource ds =
    (DataSource)ctx.lookup("java:comp/env/jdbc/ds1");

    Hope this helps.
    Hi All!

    If you are using RAD or WSAD, open your web.xml and go to References Tab, select your referene (i.e., datasource). In Websphere Bindings section enter the jndi name of the datasource (jdbc/yourdatasourcename), check Use default method and enter Authentication alias as entered while creating the datasource (like DB2ADMIN / USER / SCOT etc.,) and restart your server.

    Thanks and Regards
    Tummala Sreenivas
    Singapore
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-02-03T14:54:21Z  
    i am also using WSAD 5.1.2 still facing the same problem .did u solve this, if yes pls help me
    > i am also using WSAD 5.1.2 still facing the same
    > problem .did u solve this, if yes pls help me

    I was having the same problem, but I solved it.
    You only 've to use "jdbc/myDatasourceName". Don't write "java:comp/env/jdbc"

    I hope help you.

    Bye
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-02-12T07:23:48Z  
    Sorry, the above link was messed up. Try:

    http://publib.boulder.ibm.com/infocenter/wasinfo/topic/com.ibm.wasee.doc/info/ee/asyncbns/tasks/tasb_epasb.html
    According to the attached article the DataSource cannot be looked up from a spun off thread.
    Does it mean that the Spring framework cannot be used with Websphere?
    Spring connects to the datasource from its own thread.

    rad6 user
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-03-07T10:23:59Z  
    Hi,
    I have the same problem , but slightly different from the above said ones. I have an application which runs many threads and is loaded from a servlet. I have a Datasource configured and have a resource reference defined for the purpose.

    I am able to get the reference to this Datasource through Resource reference when called directly from the servlet's thread. But if one of the other threads (application threads) tries to access the Datasource I get the exception " javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:" ". I have a utility class which returns the datasource and I get exception when the same is called from a different thread other than the main servlet thread. This is true only for Resource reference lookups (in my case java:comp/env/jdbc/sample). I am able to get the reference , both from servlet thread and the other threads ,if i directly use the jndi binding (in my case it is jdbc/sample). I am confused about how to proceed , I can get away by directly using the acutal JNDI name and not Resource Reference, but I get some messages in log when i do that and I have read somewhere that it happens when you dont access the resource through a resource reference.

    Could this be a bug with Websphere or I am missing some important detail of configuring. I tried this on both the Test Environment and Base version with Deployment Manger. Attaching is the Servlet I used for testing.

    Source

    import java.io.IOException;
    import javax.naming.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.sql.DataSource;
    import com.test.TestContext;

    class MyThread extends Thread{
    public void run() {
    try {
    InitialContext context = new InitialContext();
    DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/avs1sun");
    System.out.println("Datasource = " + ds);
    }catch (Exception e ){
    e.printStackTrace();
    }
    }
    }

    public class TestServlet extends HttpServlet implements Servlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    MyThread t = new MyThread();
    System.out.println("Running using Servlet's main Thread");
    t.run();
    System.out.println("Now running using a new Thread");
    t.start();
    }
    }
    Result


    12/17/04 23:32:14:219 IST 3c9bcae3 WsServer A WSVR0001I: Server server1 open for e-business
    12/17/04 23:32:17:547 IST 68d08ae1 WebGroup I SRVE0180I: AVSCoreAppWeb [/AVSCoreAppWeb] http://Servlet.LOG: TestServlet: init
    12/17/04 23:32:17:562 IST 68d08ae1 SystemOut O Running using Servlet's main Thread
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Datasource = com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource@4835caed
    12/17/04 23:32:17:578 IST 68d08ae1 SystemOut O Now running using a new Thread
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1663)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1009)
    12/17/04 23:32:17:594 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:932)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1261)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:194)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:135)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at javax.naming.InitialContext.lookup(InitialContext.java:360)
    12/17/04 23:32:17:609 IST 6ae98ae1 SystemErr R at MyThread.run(TestServlet.java:17)
    I have the same issue. did u have any fix for it?
    If so please let me know.

    Thanks
    shanmugam.ve
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-03-07T21:25:31Z  
    I have the same issue. did u have any fix for it?
    If so please let me know.

    Thanks
    shanmugam.ve
    I had the same problem with the deprecated warnings. I fixed it by doing the following.

    Data sources should be looked up using the alias name you have defined, but then prefixed with java:comp/env. You can create data sources either through the admin site or through the RAD IDE by opening up the web.xml.

    1. Create a datasource named: MYDataSourceDB
    2. Create it with the JNDI name of: jdbc/OraclePooledQa (this name is specific to my application server - Orion). Yours might be different.
    3. Lookup for the database is done by:
    ds = (DataSource) initialContext.lookup(java:comp/env/MYDataSourceDB)

    NOTE: #3 and #1 are tsame, just in #3 it's prefixed with java:comp/env/
    Hope that helps.
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-03-07T21:28:28Z  
    According to the attached article the DataSource cannot be looked up from a spun off thread.
    Does it mean that the Spring framework cannot be used with Websphere?
    Spring connects to the datasource from its own thread.

    rad6 user
    Anyone have any information on this question? I have my JNDI lookups working fine for the main thread, but we have some user threads in our application and they are throwing NamingExceptions. It appears that the last poster is correct and user threads can't access the JNDI context that the application server can. How do I fix this?
    Thanks.
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-04-11T09:50:28Z  
    I had the same problem with the deprecated warnings. I fixed it by doing the following.

    Data sources should be looked up using the alias name you have defined, but then prefixed with java:comp/env. You can create data sources either through the admin site or through the RAD IDE by opening up the web.xml.

    1. Create a datasource named: MYDataSourceDB
    2. Create it with the JNDI name of: jdbc/OraclePooledQa (this name is specific to my application server - Orion). Yours might be different.
    3. Lookup for the database is done by:
    ds = (DataSource) initialContext.lookup(java:comp/env/MYDataSourceDB)

    NOTE: #3 and #1 are tsame, just in #3 it's prefixed with java:comp/env/
    Hope that helps.
    great!

    The key is to use resource reference name.
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-04-26T15:06:11Z  
    I had the same problem with the deprecated warnings. I fixed it by doing the following.

    Data sources should be looked up using the alias name you have defined, but then prefixed with java:comp/env. You can create data sources either through the admin site or through the RAD IDE by opening up the web.xml.

    1. Create a datasource named: MYDataSourceDB
    2. Create it with the JNDI name of: jdbc/OraclePooledQa (this name is specific to my application server - Orion). Yours might be different.
    3. Lookup for the database is done by:
    ds = (DataSource) initialContext.lookup(java:comp/env/MYDataSourceDB)

    NOTE: #3 and #1 are tsame, just in #3 it's prefixed with java:comp/env/
    Hope that helps.
    I've tried it like that, but it does not help :(
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-04-26T15:08:06Z  
    Check your ibm-web-bnd.xmi It should have binding information for the jndi name like

    resRefBindings xmi:id="ResourceRefBinding_xxxxxxx" jndiName="jdbc/testDataSource"

    You can add it using IDE by editing web.xml
    Refrences --> Resource and selecting the Resource Refrence in this case it was e.g jdbc/testDataSource.
    I've tried to change web.xml as well as ibm-web-bnd.xmi as it was suggested, but it gave no success... Any suggestions?
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-04-26T16:23:17Z  
    I had the same problem with the deprecated warnings. I fixed it by doing the following.

    Data sources should be looked up using the alias name you have defined, but then prefixed with java:comp/env. You can create data sources either through the admin site or through the RAD IDE by opening up the web.xml.

    1. Create a datasource named: MYDataSourceDB
    2. Create it with the JNDI name of: jdbc/OraclePooledQa (this name is specific to my application server - Orion). Yours might be different.
    3. Lookup for the database is done by:
    ds = (DataSource) initialContext.lookup(java:comp/env/MYDataSourceDB)

    NOTE: #3 and #1 are tsame, just in #3 it's prefixed with java:comp/env/
    Hope that helps.
    I've solved the problem on my side:

    I had to look up with the pure datasource JNDI name (without any prefix!) like that:
    jdbc/OraclePooledQa

    No "java:comp/env" before...

    The lookup is being done from Hibernate, so I have something like the following in my hibernate.cfg.xml file:

    <property name="connection.datasource">
    jdbc/OraclePooledQa
    </property>

    Regards,
    Andrey
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-05-02T13:38:17Z  
    Hi All!

    If you are using RAD or WSAD, open your web.xml and go to References Tab, select your referene (i.e., datasource). In Websphere Bindings section enter the jndi name of the datasource (jdbc/yourdatasourcename), check Use default method and enter Authentication alias as entered while creating the datasource (like DB2ADMIN / USER / SCOT etc.,) and restart your server.

    Thanks and Regards
    Tummala Sreenivas
    Singapore
    Here is the detailed solution:
    I was facing the same problem and came across with this thread.
    I found the solution, solved it and thought would share with you all.

    1. you can remove "java:comp/env/" part. It will work, but you will get the following warning..
    I J2CA0122I: Resource reference jdbc/myDataSource could not be located, so default values of the following are used: Resource-ref settings

    2. Good thing is to create reference alias
    have a look at this link for detailed solution.. it worked for me
    http://www.webspherepower.com/issuesprint/issue200410/00001357.html
  • SystemAdmin
    SystemAdmin
    1215 Posts

    Re: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".

    ‏2006-05-29T23:59:01Z  
    Hi All!

    If you are using RAD or WSAD, open your web.xml and go to References Tab, select your referene (i.e., datasource). In Websphere Bindings section enter the jndi name of the datasource (jdbc/yourdatasourcename), check Use default method and enter Authentication alias as entered while creating the datasource (like DB2ADMIN / USER / SCOT etc.,) and restart your server.

    Thanks and Regards
    Tummala Sreenivas
    Singapore
    HI ,,

    i am trying to lookup DataSource from my entity bean ,but when i run it on UTC it gives me this Exception , can u help me with this.

    Bean method

    try{
    InitialContext jndiContext = new InitialContext();
    DataSource dataSource = (DataSource)jndiContext.lookup
    ("java:comp/env/jdbc/TECHBOOK");

    return dataSource.getConnection();
    }

    in EJB diployment des


    i have

    JNDI - CMP Connection Factory Binding
    JNDI Name - jdbc/TECHBOOK

    i have a reference

    name - TechbookDS

    under , WebSphere Bindings

    JNDI name - jdbc/TECHBOOK

    ,,,, when i deploy this on UTC , it give me this error ,

    E CNTR0019E: Non-application exception occurred while processing method "create". Exception data: com.ibm.ejs.container.CreateFailureException: ; nested exception is:
    javax.ejb.EJBException: nested exception is: javax.naming.NameNotFoundException: Name "comp/env/TECHBOOK" not found in context "java:".
    can u please tell me what should do for this