你用的是什么容器?
ejb/DataSourceName
是否在容器中设置DataSourceName

解决方案 »

  1.   

    private EJBHome home = null;
      private void setHome(String ejbName, Class ejbHome) throws Exception
        {      try
          {
            Context ctx = new InitialContext();
            Object ref = ctx.lookup(ejbName);
            this.home = (EJBHome) PortableRemoteObject.narrow(ref, ejbHome);
           }
           catch(Exception ee)
           {
             System.out.println("EJB "+ejbName+" setHome "+" error is "+ee.getMessage());
           }
        }      this.setHome("SessionEJB", SessionHome.class);
          SessionRemote remote = ((SessionHome) home).create();
      

  2.   

    String dbName = ic.lookup("DataSourceName");????????
    <!--
    The env-entry-name element contains the name of an enterprise bean's
    environment entry.  The name is a JNDI name relative to the
    java:comp/env context.  The name must be unique within an enterprise bean.Used in: env-entryExample:<env-entry-name>minAmount</env-entry-name>
    -->
      

  3.   

    String dbName = ic.lookup("java:comp/env/jdbc/DataSourceName");
      

  4.   

    to  cxjxue  
    如果你的容器是J2EE RI的话,那么你试试这样
    try
    {
      Context ctx=new InitialContext();
      String str=(String)ctx.lookup("java:comp/env/DataSourceName");
    }
    catch(Exception e){//catch exception}以上代码是根据你的部署描述符写的。
      

  5.   

    你用的是什么application server?
      

  6.   

    非常谢谢各位的回复
    我用的是weblogic6.1 weblogic中的连接池和Data Source 已经设置好了
    to wcarry21(开开) :我看不懂你程序的意思,能详细一点吗?
    to: xioyoo(丁鹏) :非常谢谢!
    能给我讲讲"java:comp/env/DataSourcename"含义吗?
    ggyy(发誓:再也不丢钱包了) :也非常谢谢你,我想知道为什么你的和xioyoo(丁鹏) 的有点区别,加jdbc是什么意思?下班时结分~~~
      

  7.   

    嗬嗬!
     笔误!
    主要是经常采用:jdbc/XXXXX来标记是jdbc连接的
    所以习惯了。
     不好意思
      

  8.   

    The name is a JNDI name relative to the
    java:comp/env context
      

  9.   

    首先,你必须正确配置了jndi.properties,然后用xioyoo(丁鹏) 的方法就可以了,一般情况下可以找到“java:comp/env/“,如果说找不到"env"那你就的配置你的jndi环境了
      

  10.   

    weblogic 中你可以使用如下代码,这是weblogic的例子代码,
      private Context getInitialContext() throws NamingException {    try {
          // Get an InitialContext
          Properties h = new Properties();
          h.put(Context.INITIAL_CONTEXT_FACTORY,
              "weblogic.jndi.WLInitialContextFactory");
          h.put(Context.PROVIDER_URL, url);
          return new InitialContext(h);
        } catch (NamingException ne) {
          log("We were unable to get a connection to the WebLogic server at "+url);
          log("Please make sure that the server is running.");
          throw ne;
        }
      }    Context ctx = getInitialContext();    try {
          Object home = (AccountHome) ctx.lookup("java:comp/env/DataSourceName");
          return (AccountHome) PortableRemoteObject.narrow(home, AccountHome.class);    } catch (NamingException ne) {
          log("The client was unable to lookup the EJBHome.  Please make sure " +
          "that you have deployed the ejb with the JNDI name " + 
          "containerManaged.AccountHome on the WebLogic server at "+url);      throw ne;
        }
      

  11.   

    多谢各位
    谢谢后来的zombieLi(zombieLi) 
    我才刚刚开始学java,你讲的有些东西我还不懂,如:Properties 
    还有我怎么找不到jndi.properties文件啊?
    算了,以后再问,再次多谢各位。