C
Chris Smith
Rico said:From what I understand, just a matter of having the c3p0.jar in the
effective classpath; adding the following code and getting connections
from the DataSource:
import com.mchange.v2.c3p0.*;
...
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass( "org.postgresql.Driver" ); //loads the jdbc driver
cpds.setJdbcUrl( "jdbcostgresql://localhost/testdb" );
cpds.setUser("dbuser");
cpds.setPassword("dbpassword");
That would work, but it's not ideal.
Coz there's this part:
"You can easily configure Apache's Tomcat web application server to use
c3p0 pooled DataSources. Below is a sample config to get you started.
It's a fragment of Tomcat's conf/server.xml file, which should be
modified to suit and placed inside a <Context> element."
That is ideal. The idea behind a data source is that your code doesn't
care where the connections are coming from. If you add the above code
to your project, then you have to recompile your code to connect a
database other than PostgreSQL on localhost; not the best idea in the
world. By placing the configuration in server.xml, you can change the
database configuration by editing a config file. You'll still aquire
the data source by the same JNDI name, and your code will be identical
when you connect to a database somewhere else.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation