Posted By:
Anonymous
Posted On:
Thursday, February 20, 2003 12:47 AM
Hi, everybody. In my web application, I need to establish and use several times a connection to the same database. So, I created a ConnectionPoolDataSource object, I set the parameters of my database in its attributes, and I made a static method that returns, each time it's called, a new handle (Connection), by calling the PooledConnection.getConnection() method. I'm attaching the code here below: public class PvswDataSource extends com.pervasive.jdbc.v2.ConnectionPoolDataSource{ private static javax.sql.PooledConnection connPool = null; // Constructor: configure the object itself and the connPool attribute public PvswDataSource(String ipAddress, String port, String d
More>>
Hi, everybody.
In my web application, I need to establish and use several times a connection to the same database.
So, I created a ConnectionPoolDataSource object, I set the parameters of my database in its attributes, and I made a static method that returns, each time it's called, a new handle (Connection), by calling the PooledConnection.getConnection() method.
I'm attaching the code here below:
public class PvswDataSource extends com.pervasive.jdbc.v2.ConnectionPoolDataSource{
private static javax.sql.PooledConnection connPool = null;
// Constructor: configure the object itself and the connPool attribute
public PvswDataSource(String ipAddress, String port, String dbName) throws SQLException{
super();
// configure the data source...
this.setServerName(ipAddress);
this.setPortNumber(port);
this.setDatabaseName(dbName);
try{
// get the connection pool:
this.connPool = this.getPooledConnection();
}catch(SQLException se){throw se;}
}
// Method which return the physical connection
public static Connection getConnection() throws SQLException{
Connection conn = null;
if (null != connPool){
try{
conn = connPool.getConnection();
return conn;
} catch(SQLException se){throw se;}
}else throw new SQLException("");
}
}
Each time I need a connection, I call the getConnection() method, I use the connection and then I close it.
I have two questions, if someone can help me...
1) Monitoring (with a tool) the active connections to the database, I've realized that there's a unique connection open during all the time the application is running, that it's not what I expected to see.
This connection gets opened when the PooledConnection object is created and never gets closed, unless the server is stopped.
Is there something wrong in my code or I likely have to properly configure my database, or the ODBC engine?
2) Which advantages would I get if I used the JNDI service, instead of defining the DataSource as I described?
Any kind of help will be very appreciated!!
<<Less