I am a JavaSE user, writing a standalone web server not using Tomcat or Glassfish.
MySQL Connector/J(http://dev.mysql.com/doc/connector-j/en/connector-j-overview.html) does not seem to offer an example.
Thanks in advance.
I am a JavaSE user, writing a standalone web server not using Tomcat or Glassfish.
MySQL Connector/J(http://dev.mysql.com/doc/connector-j/en/connector-j-overview.html) does not seem to offer an example.
Thanks in advance.
Finally I switched to Apache DBCP, its example code is not informative, so I leave my code here for future reference.
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
String.format("jdbc:mysql://%s:%d/%s", host, port, db), null);
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
connectionFactory, null);
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(100);
ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(
poolableConnectionFactory, poolConfig);
poolableConnectionFactory.setPool(connectionPool);
PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(
connectionPool);
return dataSource;
DBCP test code is more informative than its example(https://github.com/apache/commons-dbcp/blob/trunk/src/test/java/org/apache/commons/dbcp2/TestPoolingDriver.java)