Creates a real database connection, failing if one is not obtained in the specified time.
@param timeoutMillis The timeout in milliseconds.
@return The connection.
@throws SQLException on connection problem or timeout waiting for connection.
482536
private Connection createRealConnection(final long timeoutMillis) throws SQLException {

      if(timeoutMillis < 1L) {

         String usePassword = getPassword();

         Connection conn = dbConnection.datasource == null ?
                 DriverManager.getConnection(dbConnection.connectionString, dbConnection.user, usePassword) :
                 dbConnection.datasource.getConnection(dbConnection.user, usePassword);
         if(conn != null) {
            return conn;
         } else {
            throw new SQLException("Unable to create connection: driver/datasource returned [null]");
         }

      } else {

         try {
            return connectionTimeLimiter.callWithTimeout(() -> createRealConnection(0L), timeoutMillis, TimeUnit.MILLISECONDS);
         } catch(UncheckedTimeoutException ute) {
            throw new SQLException("Unable to create connection after waiting " + timeoutMillis + " ms");
         } catch(Exception e) {
            throw new SQLException("Unable to create connection: driver/datasource", e);
         }
      }
   }
627997
protected Connection obtainRawInternalConnection()
	throws SQLException {
		Connection result = null;

		DataSource datasourceBean = this.config.getDatasourceBean();
		String url = this.config.getJdbcUrl();
		String username = this.config.getUsername();
		String password = this.config.getPassword();
		Properties props = this.config.getDriverProperties();
		boolean externalAuth = this.config.isExternalAuth();
		if (externalAuth && 
				props == null){
			props = new Properties();
		}

		if (datasourceBean != null){
			return (username == null ? datasourceBean.getConnection() : datasourceBean.getConnection(username, password));
		}

		// just force the driver to init first
		if (!this.driverInitialized ){
			try{
				this.driverInitialized = true;
				if (props != null){
					result = DriverManager.getConnection(url, props);
				} else {
					result = DriverManager.getConnection(url, username, password);
				}
				result.close();
			}catch (SQLException t){
				// just force the driver to init first
				// See https://bugs.launchpad.net/bonecp/+bug/876476
			}
		}

		if (props != null){
			result = DriverManager.getConnection(url, props);
		} else { 
			result = DriverManager.getConnection(url, username, password);
		}
		// #ifdef JDK>6
		if (this.clientInfo != null){ // we take care of null'ing this in the constructor if jdk < 6
			result.setClientInfo(this.clientInfo);
		}
		// #endif JDK>6

		return result;
	}
94078
public final int getLoginTimeout() throws SQLException {
        try {
            if(!Driver.class.equals(type)) {
                return ((CommonDataSource) dataSourceOrDriver).getLoginTimeout();
            }
            //Return that the default value is being used when using the Driver type
            return 0;
        } catch (SQLException sqlX) {
            FFDCFilter.processException(sqlX, getClass().getName(), "1670", this);
            throw AdapterUtil.mapSQLException(sqlX, this);
        }
    }
311198
public SQLException exceptionWithQuery(ParameterHolder[] parameters, SQLException sqlEx,
      PrepareResult serverPrepareResult) {
    if (sqlEx.getCause() instanceof SocketTimeoutException) {
      return new SQLException("Connection timed out", CONNECTION_EXCEPTION.getSqlState(), sqlEx);
    }
    if (options.dumpQueriesOnException) {
      return new SQLException(exWithQuery(sqlEx.getMessage(), serverPrepareResult, parameters),
          sqlEx.getSQLState(),
          sqlEx.getErrorCode(), sqlEx.getCause());
    }
    return sqlEx;
  }
978816
public void setConnectTimeout(int timeout) {
        Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
        this.httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
    }
982060
public final Connection connectNow(Duration timeout) {
		Objects.requireNonNull(timeout, "timeout");
		try {
			return Objects.requireNonNull(connect().block(timeout), "aborted");
		}
		catch (IllegalStateException e) {
			if (e.getMessage().contains("blocking read")) {
				throw new IllegalStateException("TcpClient couldn't be started within "
						+ timeout.toMillis() + "ms");
			}
			throw e;
		}
	}
1261819
public static Connection getConnection(final String jdbcURL) throws SQLException {
        try {
            return getRealConnection(jdbcURL);
        } catch (final SQLException sqlException) {
            try {
                return (Connection) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws Exception {
                        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
                        if (cl != null && cl != DriverManagerAccessor.class.getClassLoader()) {
                            final Class<?> definedClass = DriverManagerAccessorSupport.define(cl);
                            final Method method = definedClass.getDeclaredMethod("getRealConnection", String.class);
                            method.setAccessible(true);
                            return (Connection) method.invoke(null, jdbcURL);

                        } else {
                            throw sqlException;
                        }
                    }
                });
            } catch (PrivilegedActionException e) {
                throw sqlException;
            }
        }
    }
577151
public Connection getConnection() throws SQLException {
		Connection connection = this.pool.getConnection();

		// set the Transaction Isolation if defined
		try {
			// set the Transaction Isolation if defined
			if ((this.isolation != null) && (connection.getTransactionIsolation() != this.isolation.intValue())) {
				connection.setTransactionIsolation (this.isolation.intValue());
			}

			// toggle autoCommit to false if set
			if ( connection.getAutoCommit() != this.autocommit ){
				connection.setAutoCommit(this.autocommit);
			}

			return connection;
		} catch (SQLException e){
			try {
				connection.close();
			} catch (Exception e2) {
				logger.warn("Setting connection properties failed and closing this connection failed again", e);
			}

			throw e;
		}
	}
895495
public static RedisCommandTimeoutException createTimeoutException(String message, Duration timeout) {
        return new RedisCommandTimeoutException(
                String.format("%s. Command timed out after %s", message, formatTimeout(timeout)));
    }
830983
public static MariaDbConnection newConnection(UrlParser urlParser, GlobalStateInfo globalInfo)
      throws SQLException {
    if (urlParser.getOptions().pool) {
      return Pools.retrievePool(urlParser).getConnection();
    }

    Protocol protocol = Utils.retrieveProxy(urlParser, globalInfo);
    return new MariaDbConnection(protocol);
  }
214011
public void setNetworkTimeout(Executor executor, final int milliseconds) throws SQLException {
    if (this.isClosed()) {
      throw ExceptionMapper
          .getSqlException("Connection.setNetworkTimeout cannot be called on a closed connection");
    }
    if (milliseconds < 0) {
      throw ExceptionMapper
          .getSqlException("Connection.setNetworkTimeout cannot be called with a negative timeout");
    }
    SQLPermission sqlPermission = new SQLPermission("setNetworkTimeout");
    SecurityManager securityManager = System.getSecurityManager();
    if (securityManager != null) {
      securityManager.checkPermission(sqlPermission);
    }
    try {
      stateFlag |= ConnectionState.STATE_NETWORK_TIMEOUT;
      protocol.setTimeout(milliseconds);
    } catch (SocketException se) {
      throw ExceptionMapper.getSqlException("Cannot set the network timeout", se);
    }
  }
141184
public synchronized Connection getConnection() throws SQLException {
        if ((currentTimeMillis() - lastChecked)
        > VALIDITY_CHECK_INTERVAL) {
            logger.trace("Checking connection validity");
            // check the validity of the connection
            boolean valid = false;
            int t = 0;

            while (!valid && t < REATTEMPTS) {
                try {
                    if (connection == null || connection.isClosed()
                            || !connection.isValid(VALIDITY_TIMEOUT)) {
                        logger.info(
                                "Connection to {} is closed or invalid; attempting to re-establish",
                                url);
                        // remove any cached prepared statements for this connection
                        threadedPsMap.remove();

                        // attempt re-establishment
                        this.connection = DriverManager
                                .getConnection(url, user, pass);
                        logger.info("Re-established connection to {}", url);
                        // do not set valid to true - check this new connection
                    } else {
                        valid = true;
                    }
                } catch (SQLException e) {
                    logger.info("Failed to re-establish connection to " +
                            "{}, try {}/{}; Reason: {}",
                            new Object[] { url, t, REATTEMPTS, e.getMessage() });
                    // set connection to null to prevent the same error from continuously
                    // occurring when checking isClosed() or isValid()
                    this.connection = null;
                }
                t++;
            }
            if (!valid) {
                logger.error(
                        "Failed to re-establish a connection to {} after {} attempts",
                        url, REATTEMPTS);
                throw new SQLException(
                        "Unable to re-establish a valid connection",
                        new DBConnectionFailure(url,
                                "Unable to re-establish a valid connection"));
            }
            this.lastChecked = currentTimeMillis();
        }
        return connection;
    }
401901
public final Connection getConnection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
        String url = "jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database + "?user=" + this.username + "&password="
                + this.password + "&autoReconnect=true" + "&failOverReadOnly=false&maxReconnects=3";
        DriverManager.registerDriver((Driver) Class.forName("com.mysql.jdbc.Driver").newInstance());
        return DriverManager.getConnection(url);
    }
657337
protected Connection openConnection() throws SQLException
   {
      return SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
      {
         public Connection run() throws SQLException
         {
            return ds.getConnection();
         }
      });
   }
666363
public static Timeout create(long timeout, TimeUnit timeUnit) {

        LettuceAssert.notNull(timeUnit, "TimeUnit must not be null");

        return new Timeout(Duration.ofNanos(timeUnit.toNanos(timeout)));
    }
398140
private Connection getConnection() throws SQLException {
        return JDBC.connect(model.getDriver(), model.getUrl(),
                            model.getUser(), model.getPassword());

    }
135423
Connection getConnection() throws SQLException {
		if (connection == null) {
			connection = connectionSupplier.getConnection();
			initSavepoints(connection);
		}
		return connection;
	}