O'Reilly logo

J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software by Art Taylor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required