tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Rowe <ichabo...@gmail.com>
Subject Re: jndi question
Date Mon, 22 Aug 2005 14:24:10 GMT
Thanks for responding Dirk.  I've practically memorized the 
documentation on the link you sent:

// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

// Look up our data source
DataSource ds = (DataSource)
  envCtx.lookup("jdbc/EmployeeDB");

// Allocate and use a connection from the pool
Connection conn = ds.getConnection();
... use this connection to access the database ...
conn.close();

Whenever I try this, here's what I get (which led me to trying it the way I posted):

javax.naming.NameNotFoundException: Name java:comp is not bound in this Context

Any ideas?  Thanks again.
Sean



Dirk Weigenand wrote:

>Hi Sean,
>
>  
>
>>--- Urspr√ľngliche Nachricht ---
>>Von: Sean Rowe <ichabooka@gmail.com>
>>An: tomcat-user@jakarta.apache.org
>>Betreff: jndi question
>>Datum: Mon, 22 Aug 2005 01:26:49 -0500
>>
>>I have tried for several hours now to get connection pooling for my 
>>MySql database to work, but have been unable to do so.  I keep getting 
>>this error:
>>
>>javax.naming.NoInitialContextException: Cannot instantiate class:
>>org.apache.commons.dbcp.BasicDataSourceFactory
>>
>>
>>    
>>
> 
>  
>
>>It's bombing out on this code:
>>
>>    Properties p=new Properties();
>>     
>>
>>    
>>
>p.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.commons.dbcp.BasicDataSourceFactory");
>  
>
>>     p.put(Context.PROVIDER_URL,"jdbc:mysql://localhost:3306");
>>     Context initCtx = new InitialContext(p); // here's where it dies
>>
>>    
>>
>
>You're mixing up some concepts here. Context.INITIAL_CONTEXT_FACTORY is
>meant to provide the name of a factory producing JNDI contexts, not a
>factory for producing JDBC DataSources. The same goes for the next line of
>code. Context.PROVIDER_URL is not used for providing information about a
>database connection.
>
>There is extensive documentation on the tomcat web site regarding JNDI
>ressource configuration. Have a look at the following URL:
>
>http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html
>
>  
>
>>Can someone please help me, or at least point me in the direction of 
>>some documentation that I've missed?  I've searched google and every 
>>other search engine I can think of.  Thanks in advance.
>>
>>Sean Rowe
>>
>>    
>>
>
>Regards
>        Dirk
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message