0
我有一個應用程序在連接數據庫時需要使用連接池。問題是,該應用程序被設計用於即時配置和更改連接設置。我寫了下面的代碼,它們允許我動態地創建數據源,然後使用它來打開到數據庫的連接。但是,此代碼是爲DataDirect驅動程序編寫的,我已將其用於連接到Oracle和MS SQL。不幸的是,DataDirect Mysql驅動程序只能連接到商業版本的mysql,而不是免費版本。所以現在我試圖用mysql中的connect/j完成相同的任務。我找不到如何通過類似於DD驅動程序的方法調用來設置在外部(靜態)數據源定義中找到的連接屬性。任何幫助,將不勝感激。需要動態創建MySQL Connect/J連接池的數據源
BaseDataSource bds = (BaseDataSource)ds;
// Populate the DataSource
bds.setDescription("Driver Data Source");
bds.setServerName(connectUrl);
bds.setUser(userName);
bds.setPassword(password);
if (spyAttr.length() > 0) bds.setSpyAttributes(spyAttr);
// Create the PooledConnection DataSource. Pass the data source created above
// to the PooledConnection DataSource
pds = new PooledConnectionDataSource();
pds.setDescription("Pooled Data Source");
pds.setDataSourceName("myDataSource", bds);
pds.setPoolName("myPool");
pds.setInitialPoolSize(nPoolSize);
pds.setMinPoolSize(minPoolSize);
pds.setMaxPoolSize(maxPoolSize);
pds.setPropertyCycle(propCycle);
pds.setMaxIdleTime(maxIdleTime);
pds.setTracing(tracing);
// Get connection
pds.getConnection();