我使用MysqlConnectionPoolDataSource。我不得不从jndi定义迁移到自定义解决方案。 旧的定义如下:
<data-source
name="MySqlDS" location="jdbc/MySqlPooledDS"
class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"
max-connections="100"
min-connections="5"
inactivity-timeout="200"
wait-timeout="10"
username="USERNAME"
password="PASSWORD"
url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=Cp1251"
/>
我想用这段代码替换它:
DataSource dataSource = (DataSource) Class.forName(driver.getType()).newInstance();
new Statement(dataSource, "setUrl", new Object[]{ driver.getUrl().getValue() }).execute();
new Statement(dataSource, "setUser", new Object[]{ driver.getUser().getValue() }).execute();
new Statement(dataSource, "setPassword", new Object[]{ driver.getPassword().getValue() }).execute();
new Statement(dataSource, "setUseUnicode", new Object[]{ "yes".equals(driver.getUseUnicode().getValue()) }).execute();
new Statement(dataSource, "setCharacterEncoding", new Object[]{ driver.getCharacterEncoding().getValue() }).execute();
我想在dataSource上定义max-connections
属性,但我不知道该怎么做。有什么想法吗?
感谢。