Example usage for org.apache.commons.dbcp PoolableConnectionFactory setValidationQueryTimeout

List of usage examples for org.apache.commons.dbcp PoolableConnectionFactory setValidationQueryTimeout

Introduction

In this page you can find the example usage for org.apache.commons.dbcp PoolableConnectionFactory setValidationQueryTimeout.

Prototype

public void setValidationQueryTimeout(int timeout) 

Source Link

Document

Sets the validation query timeout, the amount of time, in seconds, that connection validation will wait for a response from the database when executing a validation query.

Usage

From source file:com.foxelbox.foxbukkit.database.DatabaseConnectionPool.java

private DatabaseConnectionPool() {
    try {/*from w  ww. j a v a 2 s .  c o m*/
        Class.forName("com.mysql.jdbc.Driver");
    } catch (Exception e) {
        System.err.println("Error loading JBBC MySQL: " + e.toString());
    }

    GenericObjectPool connectionPool = new GenericObjectPool(null);
    connectionPool.setMaxActive(10);
    connectionPool.setMaxIdle(5);
    connectionPool.setTestOnBorrow(true);
    connectionPool.setTestOnReturn(true);
    connectionPool.setTestWhileIdle(true);

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
            FoxBukkit.instance.configuration.getValue("database-uri",
                    "jdbc:mysql://localhost:3306/foxbukkit_database"),
            FoxBukkit.instance.configuration.getValue("database-user", "root"),
            FoxBukkit.instance.configuration.getValue("database-password", "password"));
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            connectionPool, new StackKeyedObjectPoolFactory(), "SELECT 1", false, true);
    poolableConnectionFactory.setValidationQueryTimeout(3);

    dataSource = new PoolingDataSource(connectionPool);

    try {
        initialize();
    } catch (SQLException exc) {
        System.err.println("Error initializing MySQL Database");
        exc.printStackTrace();
    }
}