You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by garrett smith <ja...@yahoo.com> on 2002/08/28 19:10:14 UTC

Can I create InitialContext with properties file?

Hey,

I made a program called WebPool that has a main for testing purposes. (I am not
using JUnit yet). It's not working, though!

I get these errors when trying to create an initial context:

java com/dhtmlkitchen/login/db/WebPool                                         
                       
java.lang.ClassCastException: com.dhtmlkitchen.login.db.WebPool
java.lang.ClassCastException: com.dhtmlkitchen.login.db.WebPool
        at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
        at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246)
        at javax.naming.InitialContext.init(InitialContext.java:222)
        at javax.naming.InitialContext.<init>(InitialContext.java:198)
        at com.dhtmlkitchen.login.db.WebPool.init(WebPool.java:59)
        at com.dhtmlkitchen.login.db.WebPool.main(WebPool.java:80)



Here's the init method that is called from main:

    public void init() throws Exception {
            
        if (ds != null) return;
            
        ResourceBundle SQL = ResourceBundle.getBundle("jndi");

        Hashtable env = new Hashtable(9);

    
        env.put(Context.INITIAL_CONTEXT_FACTORY, this);
        env.put("factory", SQL.getString("factory"));
        env.put("maxActive", SQL.getString("maxActive"));
        env.put("maxIdle", SQL.getString("maxIdle"));
        env.put("maxWait", SQL.getString("maxWait"));
        env.put("username", SQL.getString("username"));
        env.put("password", SQL.getString("password"));
        env.put("driverClassName", SQL.getString("driverClassName"));
        env.put("url", SQL.getString("url"));
        
        Context ctx = new InitialContext(env);
        
        if(ctx == null) 
            throw new Exception("No Context");

           String CONTEXT_LOOKUP_ADDRESS = SQL.getString("context.lookup");
           try{
               
               ds = (DataSource)ctx.lookup("java:comp/env/jdbc/WebPool");
        }
        catch(Exception e){
            throw new Exception("Context Address invalid: "
                                + CONTEXT_LOOKUP_ADDRESS+" "+ e.toString());
        }
    }

I don't really know what I am doing, and this is pretty new technology. Help!





=====
http://dhtmlkitchen.com/

__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>