Hi Hen,
Vikas is right claiming that a new connection is established each
time. There seems to be missing a small part of the implementation of
your datasource class.
All the properties mentioned above are working well, but checking the
source code I found an unfinished part in SJDataSource (around line 90
in version 0.11.3).
There you placed a todo comment:
// TODO: Fix this, it pools each time, which is probably bad
Thanks for providing this hint, it helped a lot making it work.
I changed the method as follows:
------------
/** if a connection pool has been built, its url is stored in here
*/
private String poolUrl = null;
/** returns a connection to the database specified in the
properties and
* creates a connection pool, if neccessary */
public Connection getConnection(String username, String password)
throws SQLException {
String tmpUrl = this.url;
String pool = properties.getProperty("pool");
if (pool != null) { // we want a connection name named like
the pool property
synchronized (poolUrl) {
if (poolUrl == null) { // we didn't create a
connection pool already, so do i now..
PoolSetup.setupConnection(pool, url, username,
password, properties);
poolUrl = PoolSetup.getUrl(pool);
}
}
tmpUrl = poolUrl; // url is now a pooling link
}
if(username == null || password == null) {
return DriverManager.getConnection(tmpUrl);
}
return DriverManager.getConnection(tmpUrl, username,
password);
}
------------
This seems to works fine, but you have to specify a different name for
each pool that you use, if you have different databases. Since I
didn't want to introduce any new properties, I just used the pool
property, so when using two different database connections, you should
set the property not only to true, but to a unique value (see example
files below).
userdb.properties
type=javax.sql.DataSource
driver=com.sybase.jdbc2.jdbc.SybDriver
url=jdbc:sybase:Tds:
10.63.84.215:5000
pool=userdb
appdatadb.properties
type=javax.sql.DataSource
driver=com.sybase.jdbc2.jdbc.SybDriver
url=jdbc:sybase:Tds:
10.63.85.72:5000
pool=some_other_db
It would be nice if you could integrate this (or another solution)
within the next release, so I can exchange the locally patched library
with an official version.
Lars