| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 762 人关注过本帖
标题:[求助]JNDI相关!
只看楼主 加入收藏
zidom
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-6-28
收藏
 问题点数:0 回复次数:0 
[求助]JNDI相关!
package jndi;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.DirContext;
import javax.naming.directory.Attributes;
import javax.naming.NamingException;

/**
 *
 * @author Administrator
 */
public class NewClass {

    public static void main(String[] args) {
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
        try {

            // Create the initial directory context
            DirContext ctx = new InitialDirContext(env);

            // Ask for all attributes of the object
            Attributes attrs = ctx.getAttributes("cn=Ted Geisel, ou=People");

            // Find the surname attribute ("sn") and print it
            System.out.println("sn: " + attrs.get("sn").get());

        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}

/**************************************************************************
下面的是产生的异常,请问各位大哥大姐,该怎么解决?
javax. localhost:389 [Root exception is Connection refused: connect]
        at com.sun.jndi.ldap.Connection.<init>(Connection.java:207)
        at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:118)
        at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1580)
        at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2616)
        at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:287)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)
        at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
        at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:82)
        at jndi.NewClass.main(NewClass.java:28)
Caused by: Connection refused: connect
        at (Native Method)
        at (PlainSocketImpl.java:333)
        at (PlainSocketImpl.java:195)
        at (PlainSocketImpl.java:182)
        at (SocksSocketImpl.java:366)
        at (Socket.java:519)
        at (Socket.java:469)
        at (Socket.java:366)
        at (Socket.java:180)
        at com.sun.jndi.ldap.Connection.createSocket(Connection.java:349)
        at com.sun.jndi.ldap.Connection.<init>(Connection.java:184)
        ... 14 more

*********************************************************************************/
搜索更多相关主题的帖子: JNDI 
2007-12-18 18:24
快速回复:[求助]JNDI相关!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028111 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved