Hi Filip,
After using code

StandardServer server =
                        (StandardServer) ServerFactory.getServer();
                context = server.getGlobalNamingContext();

And putting the JNDI resource definition into servler.xml
<GlobalNamingResources>
element ,my connection polling code is working fine.


But my question still here is,I had JNDI loop up  code in a Listener class
which extends ServletContextListener which is working fine.(This is also
called during server start up)

And Also my start up class which was called after the listener class(bze in
tomcat log files listener was called first),then also I was getting Name
comp is not bound in this Context?????
Why the context is available to my listener class and not my start up class
even though my connection pooling code is called after the listener.

Can you explain some thing related to how is sequence of binding of
java:com/env/jdbc
objects is done
Or any links/articles which explains this.


Thanks and Regards
Hanmaya

On Thu, May 15, 2008 at 8:41 PM, Filip Hanik - Dev Lists <[EMAIL PROTECTED]>
wrote:

> this line here
>
> initContext.lookup("java:comp/env");
>
> will only work if it is run inside an application, hence you get the
> exception
>
>
> that's why I pointed you to an example, here is the link
>
> http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/DataSourceRealm.java?revision=543691&view=markup
>
> look at the method
>
> *protected* Connection open() {
>
> to see an example of how you would get hold of a JNDI datasource when
> running inside tomcat server code, and not web application code
>
> Filip
>
>
>
>
>
> Hanmay Udgiri wrote:
>
>> Hi Filip,
>> I could not understand what u meant.
>> I am calling getConnection() method which has the below code server
>> startup,like after user logs into the application and does a operation,the
>> code works.
>>
>> But If I call the getConnection method during the server start up I am
>> getting exception.
>>
>> javax.naming.NameNotFoundException: Name comp is not bound in this Context
>>
>> I have written a Listener class which implements ServletContextListener,I
>> have written the same JNDI code in that too and this works fine.
>> Here my start up class calls the getConnection() method before the my
>> Listenerclass.
>>
>> *Is the issue because the server has not fully intialized/bound the JNDI
>> objects.*
>> And My start up class is calling the getConnection() method before server
>> inialize
>>
>> System.setProperty("java.naming.factory.initial",
>> "org.apache.naming.java.javaURLContextFactory");
>>            System.setProperty("java.naming.factory.url.pkgs",
>> "org.apache.naming");
>>            Context initContext = new InitialContext();
>>            // "java:comp/env" should not be changed
>>            // it is the top of the JNDI context
>>            Context envContext = (Context)
>> initContext.lookup("java:comp/env");
>>            // "jdbc/DBLogger" is the name that will be used in
>> context.xml.default
>>            DataSource ds = (DataSource)
>> envContext.lookup("jdbc/customer");
>>            ((org.apache.tomcat.dbcp.dbcp.BasicDataSource)
>> ds).setUsername(sUserID);
>>            ((org.apache.tomcat.dbcp.dbcp.BasicDataSource)
>> ds).setPassword(sPassword);
>>            ((org.apache.tomcat.dbcp.dbcp.BasicDataSource)
>> ds).setDriverClassName(jdbcDriverClass);
>>            ((org.apache.tomcat.dbcp.dbcp.BasicDataSource)
>> ds).setUrl(jdbcDriverConnectURL + dbServiceName);
>>            System.out.println("Sucess");
>>            dbConnection = ds.getConnection();
>>
>> Thanks and Regards
>> Hanmaya
>>
>>
>> On Thu, May 15, 2008 at 6:58 PM, Filip Hanik - Dev Lists <
>> [EMAIL PROTECTED]>
>> wrote:
>>
>>
>>
>>> the best thing to do is to look into DataSourceRealm.java as part of the
>>> tomcat source code.
>>> the method open(), shows how server code would look up both a local or a
>>> global data source
>>>
>>> Filip
>>> Hanmay Udgiri wrote:
>>>
>>>
>>>
>>>> Hi
>>>> I have implemented datasource using JNDI look up.
>>>> The code work fine If I call the code during any User action.
>>>> But If try to call the same code during the tomcat server start up I get
>>>> an
>>>> exception
>>>>
>>>> javax.naming.NameNotFoundException: Name comp is not bound in this
>>>> Context
>>>>
>>>> I am using Tomcat 5.5 and Oracle 9
>>>>
>>>> I am using JNDI look for connection pooling.
>>>> We have a ITSMain class which uses MBeanServer to load the classes.
>>>> This class has a ServiceManager class which load all start up services
>>>> and
>>>> initializes it.
>>>> During this we have Connection pooling class which uses JNDI look up.
>>>> So I am getting below exception If I set my JNDI class to initialize at
>>>> start up.
>>>> But If I don't set my class to initialize at server start up,Then I
>>>> don't
>>>> get any exception.
>>>>
>>>>
>>>>
>>>>  ------------------------------------------------------------------------
>>>>
>>>> No virus found in this incoming message.
>>>> Checked by AVG. Version: 7.5.524 / Virus Database: 269.23.16/1433 -
>>>> Release Date: 5/14/2008 4:44 PM
>>>>
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>
>>>
>>
>>
>>  ------------------------------------------------------------------------
>>
>> No virus found in this incoming message.
>> Checked by AVG. Version: 7.5.524 / Virus Database: 269.23.16/1433 -
>> Release Date: 5/14/2008 4:44 PM
>>
>>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
Thanks and Regards
Hanmayya Udgiri

Reply via email to