On Thu, 14 Mar 2002, Jason R Lee wrote:
> Date: Thu, 14 Mar 2002 06:34:07 -0800
> From: Jason R Lee <[EMAIL PROTECTED]>
> Reply-To: Jakarta Commons Developers List <[EMAIL PROTECTED]>
> To: Jakarta Commons Developers List <[EMAIL PROTECTED]>
> Subject: RE: [dbcp] Works with JNDI, but some remarks...
>
> All users will definitely be application scope. To further that, it
> would probably be best to have a servlet, upon init of the container,
> start the connection pool and then register it via JNDI. Then your bean
> would be accessing that instead of creating it every time they are
> needed. The whole point behind connection pooling is for giving multiple
> objects, usually, over the scope of the application access to
> preconneted pools (sorry if this is review). Creating a new pool obj
> based on a request level scope pretty much defeats the purpose.
>
Note that Tomcat 4 does the pool creation and JNDI registration for you,
based on the parameters defined in <Resource> and <ResourceParams>
settings. All you would need to do in the init() method of your servlet
is retrieve the pool and place it in the servlet context attributes:
InitialContext initCtx = new InitialContext();
DataSource ds = (DataSource)
initCtx.lookup("java:comp/env/lev/DataSource");
getServletContext().setAttribute("dataSource", ds);
Alternatively, your application code could repeat the first two lines
above whenever it needed to grab the pool. One advantage of this approach
is that you don't need a reference to the ServletContext object to be able
to get it's attributes, so this is easier when you're righting business
logic classes that need access to the database.
> I'm actually working on dbcp at this level now. I just have a servlet
> start the pool when tomcat starts up. Pretty easy stuff. I'm interested
> in seeing how well the pool works vs. just getting a regular connection
> every time (I'm sure dbcp will smoke it).
>
> cheers,
>
> - Jason
Craig
>
> -----Original Message-----
> From: Lev Assinovsky [mailto:[EMAIL PROTECTED]]
> Sent: Thu 3/14/2002 5:23 AM
> To: Jakarta Commons Developers List
> Cc:
> Subject: [dbcp] Works with JNDI, but some remarks...
> Hello all!
> I got dbcp working through JNDI in Tomcat 4.0.4b1.
> Thank you! (I got tired of Tyrex :-))
>
> But I have several issues.
>
> My configuration server.xml is:
> <Resource name="lev/DataSource" auth="Container"
> type="javax.sql.DataSource"/>
> <ResourceParams name="lev/DataSource">
> <parameter><name>factory</name>
>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> </parameter>
>
>
> <parameter><name>username</name><value>wv</value></parameter>
>
> <parameter><name>password</name><value>wv</value></parameter>
>
> <parameter><name>maxActive</name><value>100</value></parameter>
>
> <parameter><name>maxIdle</name><value>30000</value></parameter>
>
> <parameter><name>maxWait</name><value>100</value></parameter>
> <parameter><name>driverClassName</name>
> <value>org.gjt.mm.mysql.Driver</value></parameter>
> <parameter><name>url</name>
>
> <value>jdbc:mysql://localhost:3306/WV?user=wv&password=wv</value></parameter>
> </ResourceParams>
>
> 1. When I had 'user' instead of 'username' (Tyrex allows both) I got
> NullPointer exception
> in connectionProperties.put("user", username) in BasicDataSource.
>
> 2. When I didn't have maxActive I got infinite loop in borrowObject()
> in GenericObjectPool.
>
> Actually I don't have clear understanding of the pool's parameters.
> I'all really appreciate
> if somebody could make it clear for me.
>
> Also with xml parameters above I got very often:
>
> java.sql.SQLException: Communication link failure: java.io.IOException
> at org.gjt.mm.mysql.MysqlIO.clearAllReceive(Unknown Source)
> at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(Unknown Source)
> at org.gjt.mm.mysql.MysqlIO.sqlQuery(Unknown Source)
> at org.gjt.mm.mysql.Connection.execSQL(Unknown Source)
>
> or
> NullPointerException.
>
> However I created new connection pool (through JNDI lookup) on every
> HTTP request since my bean where I did all above
> had a scope="request" (just for testing).
>
> And the last GLOBAL question. If I get datasource and connection in the
> bean, then
> the only way to have one connection pool for all users who sends HTTP
> request to my JSP (which using my bean)
> is to have the scope "application" for the bean. Am I right?
>
> Sincerely,
> --
> Lev Assinovsky Peterlink Web
> Programmer St. Petersburg, Russia
> Tel/Fax: +7 812 3275343 197022 ul.Chapigina 7?
> E-mail: [EMAIL PROTECTED]
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>
>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>