You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by JS <sm...@dcs.kcl.ac.uk> on 2003/04/10 15:36:04 UTC

Using a startup servlet with a JNDI Datasource

HI there,
has anyone out there successfully used the JNDI Datasource code for
accessing db connections in a startup servlet.If so, could u share your
knowhow pls??
Basically, I want the startup servlet to get things going and then all
other servlets in my system to use the datasource created in this startup
and then start pooling their connections from here.
I've seen some snippets of code in the archives, but nothing conclusive.

Many thanks
JS

ps - I asked earlier & got no reply.
...but what is the difference between me using DBCP with the <factory>
parameter in server.xml to use the BasicDataSourceFactory. OR Simply
setting up a JDBC DataSource which has no "factory" parameter declaration?
Thx



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


Re: Got any insight into servlets sharing a JNDI DBCP datasource??

Posted by JS <sm...@dcs.kcl.ac.uk>.
Thanks for your help Steve all the same.
I think I am actually quite close to some sort of solution and its just a
case of merging to the 2 processes I mentioned earlier.Will keep you posted.

Anyone else have any insight???
Much appreciated!

> Hi,
>
> Acutally, I was unable to lookup the JNDI data sources in a startup
> servlet due which I asked the question.
>
> Are you able to do the same?? Please let me know if you are successful.
>
> For your case, my view is you can write a Singleton class and use the
> same to get the connection from it wherever you required?
> I hope this may give you another thought.
>
> Regards,
> Pratt
>
>
>
>
>
>
>
> ----- Original Message -----
> From: "JS" <sm...@dcs.kcl.ac.uk>
> To: <to...@hotmail.com>
> Sent: Thursday, April 10, 2003 7:27 PM
> Subject: Re: Using a startup servlet with a JNDI Datasource
>
>
>> Hi,
>>
>> Basically my confusion lies in the fact that usually with thse startup
>> servlets you do the whole.........
>> ServletContext context = getServletContext();
>> context.setAttribute("CONN_POOL", pool);
>>
>> and then the remaining servlets in your system will access the pool by
>> doing something like....
>> pool=(ConnectionPool)getServletContext().getAttribute("CONN_POOL");
>> connection = pool.getconnection();
>> blah blah blah
>>
>>
>> Now if I am using DBCP say, which has the standard. code of.....
>>
>> InitialContext ic = new InitialContext();
>> Context jdbcCtx = (Context) ic.lookup("java:comp/env");
>> DataSource ds = (DataSource) jdbcCtx.lookup("jdbc/myDataSource");
>>
>> How can I let other servlets use this datasource....is it simply a
>> case of all of them doing ds.getConnection etc, or do I have to do
>> some magic with the ServletContext as before and set an attribute that
>> the servlets access.
>> I'm sure something is missing from my understanfding, so apologies for
>> the post.
>> Thx
>>
>> > Hi,
>> > I guess You get exceptions that the name not found exception from
>> > the startup servlet?
>> > But if you directly access the servlet either from GET/POST method
>> > you could locate the datasource.
>> > Is it the problem? or any other??
>> >
>> > Regards,
>> > Pratt.
>> >
>> > ----- Original Message -----
>> > From: "JS" <sm...@dcs.kcl.ac.uk>
>> > To: <to...@jakarta.apache.org>
>> > Sent: Thursday, April 10, 2003 7:06 PM
>> > Subject: Using a startup servlet with a JNDI Datasource
>> >
>> >
>> >> HI there,
>> >> has anyone out there successfully used the JNDI Datasource code for
>> >> accessing db connections in a startup servlet.If so, could u share
>> >> your knowhow pls??
>> >> Basically, I want the startup servlet to get things going and then
>> >> all other servlets in my system to use the datasource created in
>> >> this startup and then start pooling their connections from here.
>> >> I've seen some snippets of code in the archives, but nothing
>> >> conclusive.
>> >>
>> >> Many thanks
>> >> JS
>> >>
>> >> ps - I asked earlier & got no reply.
>> >> ...but what is the difference between me using DBCP with the
>> >> <factory> parameter in server.xml to use the
>> >> BasicDataSourceFactory. OR Simply setting up a JDBC DataSource
>> >> which has no "factory" parameter declaration? Thx
>> >>
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> >> For additional commands, e-mail:
>> >> tomcat-user-help@jakarta.apache.org




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


Re: Using a startup servlet with a JNDI Datasource

Posted by "Pratt.S" <to...@hotmail.com>.
Hi,
I guess You get exceptions that the name not found exception from the
startup servlet?
But if you directly access the servlet either from GET/POST method you could
locate the datasource.
Is it the problem? or any other??

Regards,
Pratt.

----- Original Message -----
From: "JS" <sm...@dcs.kcl.ac.uk>
To: <to...@jakarta.apache.org>
Sent: Thursday, April 10, 2003 7:06 PM
Subject: Using a startup servlet with a JNDI Datasource


> HI there,
> has anyone out there successfully used the JNDI Datasource code for
> accessing db connections in a startup servlet.If so, could u share your
> knowhow pls??
> Basically, I want the startup servlet to get things going and then all
> other servlets in my system to use the datasource created in this startup
> and then start pooling their connections from here.
> I've seen some snippets of code in the archives, but nothing conclusive.
>
> Many thanks
> JS
>
> ps - I asked earlier & got no reply.
> ...but what is the difference between me using DBCP with the <factory>
> parameter in server.xml to use the BasicDataSourceFactory. OR Simply
> setting up a JDBC DataSource which has no "factory" parameter declaration?
> Thx
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>

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