db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralf Baumert <ralf.baum...@phlat-labs.de>
Subject Re: Getting/releasing a connection from Torque pool
Date Wed, 23 Jul 2003 16:54:16 GMT
Hi Chris,

> I would like to know the best way to aquire a connection from the Torque
> pool and how to return that connection when finished. Currently I am
> using Torque.getConnection() to aquire a connection. Is this right? How
> to I return it once I am done?

i´m doing this in my jsps:

// get connection from pool
if (! Torque.isInit()) { Torque t = new Torque(); 
t.init(getServletContext().getInitParameter("torque-path")); }
Connection con = Torque.getConnection();
if (con == null || con.isClosed())
  throw new Exception("Could not connect to db" );

// free resources


torque-path is an absolute path to your Torque.properties file.

You can also initialize Torque at application startup with a servet. this lets 
you get rid of the first row "if(!Roque.isInit..."

here´s my init servlet:

public class TorqueInit extends HttpServlet {

Torque t;

  public void init() {

    t = new Torque();

    try {
      String path = getServletContext().getInitParameter("torque-path");
    catch(Exception e) {
        System.err.println(e.toString() );

  public void doGet(HttpServletRequest req, HttpServletResponse res) {}

params in web.xml:

        The absolute path to Torques config file


Hope this helps & regards,

Applikationsentwicklung & Consulting
Ralf Baumert

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

View raw message