-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJNDIExample.java
More file actions
61 lines (49 loc) · 2.01 KB
/
Copy pathJNDIExample.java
File metadata and controls
61 lines (49 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package java1_3.jndi;
/**
* Java 1.3 JNDI (Java Naming and Directory Interface) Example Demonstrates naming and directory services
* NOTE: This is a conceptual example. Actual JNDI requires naming service setup.
*/
public class JNDIExample
{
public static void main(String[] args)
{
System.out.println("=== Java 1.3 JNDI (Java Naming and Directory Interface) ===\n");
System.out.println("JNDI provides a standard API for accessing naming and directory services.\n");
System.out.println("Example code structure:");
System.out.println("""
import javax.naming.*;
import javax.naming.directory.*;
public class JNDIExample {
public static void main(String[] args) {
try {
// 1. Create initial context
Context ctx = new InitialContext();
// 2. Lookup object
Object obj = ctx.lookup("java:comp/env/jdbc/MyDB");
// 3. Bind object
MyObject myObj = new MyObject();
ctx.bind("myObject", myObj);
// 4. Directory operations
DirContext dirCtx = (DirContext) ctx;
Attributes attrs = dirCtx.getAttributes("cn=John,ou=People");
} catch (NamingException e) {
e.printStackTrace();
}
}
}
""");
System.out.println("\nKey Features:");
System.out.println("- Naming service access");
System.out.println("- Directory service access");
System.out.println("- LDAP support");
System.out.println("- DNS support");
System.out.println("- File system naming");
System.out.println("\nUse Cases:");
System.out.println("- Enterprise applications");
System.out.println("- J2EE/JEE applications");
System.out.println("- LDAP directory access");
System.out.println("- Resource lookup");
System.out.println("\nNote: This example is conceptual.");
System.out.println("Actual implementation requires naming service setup.");
}
}