/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DataMapper;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.dbcp2.BasicDataSource;

/**
 *
 * @author install1
 */
public class DBCPDataSource {

    public static Connection getConnection() throws SQLException {
        BasicDataSource ds = new BasicDataSource();
        try {
            settingsInit settingsInit = new settingsInit();
            ds.setDriver(new com.mysql.cj.jdbc.Driver());
            ds.setUrl(settingsInit.racetimerURL);
            ds.setUsername(settingsInit.racetimerUser);
            ds.setPassword(settingsInit.racetimerPassword);
            ds.setMaxTotal(-1);
            ds.setMinIdle(5);
            ds.setMaxIdle(-1);
            ds.setMaxOpenPreparedStatements(100);
        } catch (SQLException ex) {
            Logger.getLogger(DBCPDataSource.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ds.getConnection();
    }

    private DBCPDataSource() {
    }
}
