JNDI and DataSources
The JNDI API is integral to the use of DataSources. JNDI and DataSource objects have the potential to make the life of the Java developer and the application deployer easier. The following code snippet provides an example of using JNDI to obtain a JDBC connection.
import java.sql.*; import javax.sql.*; import javax.naming.*; import java.util.*; public class JNDIExample { public static void main( String args[] ) { Connection con=null; try { PreparedExample pe = new PreparedExample(); // // get our InitialContext from an LDAP naming service // Hashtable env = new Hashtable(); env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" ); env.put( Context.PROVIDER_URL, "ldap://localhost:389"); env.put( Context.SECURITY_AUTHENTICATION, ...
Get J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.