Example usage for java.util Hashtable put

List of usage examples for java.util Hashtable put

Introduction

In this page you can find the example usage for java.util Hashtable put.

Prototype

public synchronized V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this hashtable.

Usage

From source file:FilterExample.java

public static void main(String[] argc) throws Exception {
    Hashtable env = new Hashtable(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample");

    DirContext dctx = new InitialDirContext(env);

    String filter = "(&(cn=E*)(account>1005))";

    NamingEnumeration result = dctx.search("ou=People", filter, null);

    while (result.hasMore()) {
        SearchResult sr = (SearchResult) result.next();
        System.out.println("Result = " + sr.getName());
    }/*  ww w . ja  va2  s  .c o m*/

}

From source file:List.java

public static void main(String[] args) throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    env.put(Context.PROVIDER_URL, "file:/tmp/marketing");

    Object item = null;//from  w  w w  .  j a  va 2 s  .  c o m

    Context initCtx = new InitialContext(env);
    NamingEnumeration nl = initCtx.list("reports");

    if (nl == null)
        System.out.println("\nNo items in name list");
    else
        while (nl.hasMore()) {
            item = nl.next();
            System.out.println("item's class is " + item.getClass().getName());
            System.out.println(item);
            System.out.println("");
        }
}

From source file:Modify2Example.java

public static void main(String args[]) {
    Hashtable env = new Hashtable(11);

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample");
    try {/*from  w w  w.j av  a  2s. co  m*/
        DirContext dctx = new InitialDirContext(env);

        ModificationItem[] mods = new ModificationItem[3];
        mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("department", "sales"));
        mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("quota", "$1"));
        mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("assistant"));

        dctx.modifyAttributes("cn=Name, ou=People", mods);
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:Delete.java

public static void main(String[] args) throws Exception {
    String initalContextString = "/tmp/marketing/reports";

    if (args.length < 1) {
        System.out.println("Usage: java Delete filename");
        System.exit(-1);//from   w ww .  j a v  a  2 s  .c om
    }
    System.out.println("This program assumes the context is " + initalContextString);

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    env.put(Context.PROVIDER_URL, "file:" + initalContextString);

    Context initCtx = new InitialContext(env);
    System.out.println("Attempting to unbind " + args[0]);

    initCtx.unbind(args[0]);

    System.out.println("Done.");

}

From source file:ObjServer.java

public static void main(String args[]) throws Exception {
    ServerSocket ssock = new ServerSocket(1234);
    Hashtable hash = new Hashtable();
    hash.put("Java Source and Support", "www.java2s.com");

    while (true) {
        System.out.println("Listening");
        Socket sock = ssock.accept();

        ObjectOutputStream ostream = new ObjectOutputStream(sock.getOutputStream());
        ostream.writeObject(hash);/*  w  w  w .jav a 2  s  . c  om*/
        ostream.close();
        sock.close();
    }
}

From source file:Main.java

public static void main(String[] args) {
    Hashtable<String, String> ht = new Hashtable<String, String>();
    ht.put("1", "One");
    ht.put("2", "Two");
    ht.put("3", "Three");

    boolean blnExists = ht.containsKey("2");
    System.out.println("2 exists in Hashtable ? : " + blnExists);
}

From source file:Main.java

public static void main(String[] args) {
    Hashtable<String, String> ht = new Hashtable<String, String>();

    ht.put("1", "One");
    ht.put("2", "Two");
    ht.put("3", "Three");
    ht.clear();/*from   ww  w.  j a  v  a 2s  . com*/
    System.out.println(ht.size());
}

From source file:Main.java

public static void main(String[] s) {
    Hashtable<String, String> table = new Hashtable<String, String>();
    table.put("key1", "value1");
    table.put("key2", "value2");
    table.put("key3", "value3");

    System.out.println(table.contains("value3"));

}

From source file:Bind.java

License:asdf

public static void main(String[] args) throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    env.put(Context.PROVIDER_URL, "file:/tmp");

    Context initCtx = new InitialContext(env);
    initCtx.rebind("Susan", new Car("Toyota", "Camry"));
    Car c = (Car) initCtx.lookup("Susan");
    System.out.println(c);/*from   w  w  w  . j av a  2 s . c om*/

}

From source file:SearchControlsExample.java

public static void main(String[] argc) throws Exception {
    Hashtable env = new Hashtable(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample");

    DirContext dctx = new InitialDirContext(env);

    String filter = "(&(cn=S*)(account>1005))";

    String[] attrIDs = { "cn", "email" };
    SearchControls sc = new SearchControls();
    sc.setReturningAttributes(attrIDs);/*from  w  w w.  j ava 2 s  . co  m*/

    NamingEnumeration result = dctx.search("ou=People", filter, sc);

    while (result.hasMore()) {
        SearchResult sr = (SearchResult) result.next();
        System.out.println("Result = " + sr.getName());
    }

}