You just use a DataSource, and the server (Resin in this case) hides all
the details. In your application, you need to use the connection like
this:
Context jndi = (Context)new InitialContext().lookup("java:comp/env");
DataSource ds = (DataSource)jndi.lookup("jdbc/yourDSname");
Connection dbConn = ds.getConnection();
try {
// use your connection normally, ie dbConn.prepareStatement() etc
} finally {
// this doesn't actually close the connection.
// instead, it's returned to the pool
dbConn.close();
}
Your resource-ref config looked just fine - that's how you set up a pool
under Resin. Under other app servers, the configuration varies
(sometimes you do have to explicitly select a pooling datasource).
However, for portability's sake, I'd suggest leaving the user/password
parameters out of the pool config and put them in your application (use
getConnection(user, password)), because all app servers don't support
specifying the username and password for the DataSource. Resin's way is
more convenient though, so it's your choice.
On Thu, 2002-04-04 at 09:56, Jeff Kilbride wrote:
> Hi Victor,
>
> Thanks, but I've never really experienced any problems with the mm.mysql
> driver and I've been using it for almost 2 years. I've been using the
> DbConnectionBroker code from www.javaexchange.com for even longer and I'd
> like to start using the standard JNDI DataSource stuff instead. It's just
> confusing. I can't find a clear explanation of when to use a DataSource vs.
> a ConnectionPoolDataSource vs. a PooledConnection.
>
> Anybody who can lend some insight would be much appreciated.
>
> Thanks,
> --jeff
>
> ----- Original Message -----
> From: "Victor van Dijk" <victor@xxx.com>
> To: <resin-interest@xxx.com>
> Sent: Wednesday, April 03, 2002 2:18 PM
> Subject: RE: Help with connection pooling the *right* way...
>
>
> > Hi,
> >
> > It seems to be Ok. But you can also use the caucho MySQL driver. It is
> > supposed to be faster than the mm.mysql driver. The caucho driver is
> > already included when you install 2.0.5 .
> > Take a look at http://www.caucho.com/projects/jdbc-mysql/ for more
> > details.
> >
> > ---------------------------
> > <resource-ref>
> > <res-ref-name>jdbc/test</res-ref-name>
> > <res-type>javax.sql.DataSource</res-type>
> > <init-param driver-name="com.caucho.jdbc.mysql.Driver"/>
> > <init-param url="jdbc:mysql_caucho://localhost:3306/test"/>
> > <init-param user="XXXX"/>
> > <init-param password="XXXX"/>
> > <init-param max-connections="20"/>
> > <init-param max-idle-time="600"/>
> > </resource-ref>
> > ---------------------------
> >
> >
> > -----Oorspronkelijk bericht-----
> > Van: owner-resin-interest@xxx.com
> > [mailto:owner-resin-interest@xxx.com] Namens Jeff Kilbride
> > Verzonden: woensdag 3 april 2002 23:35
> > Aan: Resin Interest
> > Onderwerp: Help with connection pooling the *right* way...
> >
> > I'm using Resin 2.0.5 and MySQL. My current configuration looks like
> > this:
> >
> > ---------------------------
> > <resource-ref>
> > <res-ref-name>jdbc/test</res-ref-name>
> > <res-type>javax.sql.DataSource</res-type>
> > <init-param driver-name="org.gjt.mm.mysql.Driver"/>
> > <init-param
> > url="jdbc:mysql://localhost:3306/test?autoReconnect=true"/>
> > <init-param user="XXXX"/>
> > <init-param password="XXXX"/>
> > <init-param max-connections="20"/>
> > <init-param max-idle-time="600"/>
> > </resource-ref>
> > ---------------------------
> >
> > I use this resource for form based authentication and everything seems
> > to be
> > working correctly. I turned on the sql.log and I can see connections
> > being
> > created, re-used, and then closed when they timeout. Here's my question:
> > is
> > this the "correct" way to set up a connection pool with Resin and MySQL?
> > Should I be using some sort of PooledDataSource instead of using the
> > Driver
> > directly? MySQL comes with both a MysqlPooledConnection class and a
> > MysqlConnectionPoolDataSource class, but I have no idea if/when/where to
> > use
> > them.
> >
> > This is the one aspect of configuration that always confuses me. I have
> > a
> > feeling my setup is OK, but may not be the best way to do it. Can
> > somebody
> > please explain this or possibly give an example of their setup?
> >
> > Thanks,
> > --jeff
> >
>
-- Osma Ahvenlampi <oa@xxx.fi>
This archive was generated by hypermail 2.1.8 : Thu Sep 28 2006 - 20:17:00 PDT