Skip to content
VictorZeng edited this page May 12, 2016 · 3 revisions

Use the JdbcConnectionPool need instantiate PoolConfig and Properties

For example, the following

		/* poolConfig */
		PoolConfig config = new PoolConfig();
		config.setMaxTotal(20);
		config.setMaxIdle(5);
		config.setMaxWaitMillis(1000);
		config.setTestOnBorrow(true);

		/* properties */
		Properties props = new Properties();
		props.setProperty("driverClass", "com.mysql.jdbc.Driver");
		props.setProperty("jdbcUrl", "jdbc:mysql://localhost:3306/test");
		props.setProperty("username", "root");
		props.setProperty("password", "root");

		/* connection pool */
		JdbcConnectionPool pool = new JdbcConnectionPool(config, props);

		/* pool getConnection */
		Connection conn = pool.getConnection();

		...

		/* pool returnConnection */
		pool.returnConnection(conn);

More configs see the Configuration wiki.