Application Server Solutions for Microsoft IIS and ASP.NET
       solutions   products   partners   company   support   downloads         store
ServletExec Self-Help: FAQ
Back to Search >  Back to Search Results

Faq ID 389
Product JTurbo
Category DataSource
Question How can my code get a Pooled Connection from JTurbo?
Answer Use JTurbo's built-in connection pool datasource named PoolManagerDataSource.
JTurbo comes with sample programs and their source code.
One in particular [] shows how to create and use an instance of PoolManagerDataSource. Here is the code for a java method to do this:

/* creates a vendor-specific datasource instance and returns it as a generic javax.sql.DataSource */
public javax.sql.DataSource getDataSource(String server,
                                          String database,
                                          String username,
                                          String password )
  com.newatlanta.jturbo.driver.PoolManagerDataSource ds = new com.newatlanta.jturbo.driver.PoolManagerDataSource();
 // Configure the data source
 ds.setServerName( server );
 //ds.setLogWriter( new PrintWriter( System.out ) ); //only do this if
                                               //you want to enable debugging on the datasource
 //ds.setTestConnection(true); //only do this if
                     //you want to test every connection before
                     //it leaves the pool. This will slow down your app.
 ds.setDatabaseName( database );
 ds.setUser( username );
 ds.setPassword( password );
 ds.setInitialPoolSize( 3 );
 ds.setMinPoolSize( 2 );
 ds.setMaxPoolSize( 5 );
 ds.setMaxIdleTime( 60 );
 ds.setPropertyCycle( 300 );
  return ds;
Your code could then use the above method as follows:
import java.sql;

Connection con  = null;
Statement  stmt = null;
ResultSet   rs    = null;

 javax.sql.DataSource ds = getDataSource(server, database, username, password);

 // Connect to the database
 java.sql.Connection con = ds.getConnection();

 //create a statement and use it to get a resultset and then use the resultset

  if(rs != null) try {rs.close();} catch(Exception ignore) {}
  if(stmt != null) try {stmt.close();} catch(Exception ignore) {}
  if(con != null) try {con.close();} catch(Exception ignore) {} //this returns the
                                                   //connection to the pool for potential reuse,
                                                   //else you're code will be leaking connection objects and sockets.

company media information terms of use privacy policy contact us