JNDI and JDBC : JDBC JDNI « Database SQL JDBC « Java






JNDI and JDBC

/*
Java Programming with Oracle JDBC
by Donald Bales 
ISBN: 059600088X
Publisher: O'Reilly
*/


import java.sql.*;
import java.util.*;
import javax.naming.*;
import oracle.jdbc.pool.*;

public class TestDSBind {

  public static void main(String args[]) throws SQLException, NamingException {

    // For this to work you will need to create the
    // directories /JNDI/JDBC on your file system first
    Context ctx = null;
    try {
      Properties prop = new Properties();
      prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
          "com.sun.jndi.fscontext.RefFSContextFactory");
      prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
      ctx = new InitialContext(prop);
    } catch (NamingException ne) {
      System.err.println(ne.getMessage());
    }

    OracleDataSource ds = new OracleDataSource();
    ds.setDriverType("thin");
    ds.setServerName("dssw2k01");
    ds.setPortNumber(1521);
    ds.setDatabaseName("orcl");
    ds.setUser("scott");
    ds.setPassword("tiger");

    ctx.bind("joe", ds);
  }
}

           
       








Related examples in the same category