Hashtable env=new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    env.put(Context.PROVIDER_URL,"t3://localhost:7001");
    Context ctx=new InitialContext(env);

解决方案 »

  1.   

    public Connection getDbConnString() throws NamingException,SQLException
    {
    Connection conn = null;
    try {
              Context ctx = new InitialContext();
              DataSource ds = (DataSource) ctx.lookup("kdcerpds");
              conn = ds.getConnection();
         }
        catch(NamingException e)
        {      System.out.println(e.getMessage());
          throw e;
        }
        catch(SQLException e)
        {
         throw e;
        }
        return conn;
    }
      

  2.   

    你换成下面这样试试,它需要初始化环境参数的。 String url = "t3://buyc:7001";//buyc是机器名 Hashtable env = new Hashtable();
     env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
     env.put(Context.PROVIDER_URL, url); Context initctx=new InitialContext(env);不一定能成功,因为在我机子上它也不成功,但看见别人这么写。