import java.sql.Connection;
import java.sql.SQLException;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class JDBCConnect2 {
	public static void main(String[] args) {
		Hashtable env = new Hashtable();
		env.put(
			Context.INITIAL_CONTEXT_FACTORY,
			"com.sun.jndi.fscontext.RefFSContextFactory");
		env.put(Context.PROVIDER_URL, "file:/tmp/registry");
		Context ctx = null;
		try {
			ctx = new InitialContext(env);
		} catch (NamingException ne) {
			ne.printStackTrace();
		}
		DataSource ds = null;
		try {
			ds = (DataSource) ctx.lookup("jdbc/mySrc");
		} catch (NamingException ne) {
			ne.printStackTrace();
		}
		Connection con = null;
		try {
			con = ds.getConnection("mario", "thePassword");
		} catch (SQLException sqle) {
			Throwable t = sqle;
			while (t != null) {
   			System.err.println("Type: " + t.getClass().getName());
      		System.err.println("Message: " + t.getMessage());
      		System.err.println("-----");
      		t = t.getCause();
			}
		}
	}
}
