A connection to the database. Should be short-lived. No transaction active by default.

@return a new open connection.
483790
public DbConn getConn()
    {
        Connection cnx = null;
        try
        {
            Thread.interrupted(); // this is VERY sad. Needed for Oracle driver which otherwise fails spectacularly.
            cnx = _ds.getConnection();
            if (cnx.getAutoCommit())
            {
                cnx.setAutoCommit(false);
                cnx.rollback(); // To ensure no open transaction created by the pool before changing TX mode
            }

            if (cnx.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED)
            {
                cnx.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            }

            return new DbConn(this, cnx);
        }
        catch (SQLException e)
        {
            DbHelper.closeQuietly(cnx); // May have been left open when the pool has given us a failed connection.
            throw new DatabaseException(e);
        }
    }
352610
public function connection()
    {
        if (!is_object($this->db)) {
            $this->db = new \MysqliDb();
            $this->db->addConnection($this->dbName, $this->database);
        }

        return $this;
    }
1363550
public static SQLiteConnectionPool open(com.couchbase.lite.internal.database.sqlite.SQLiteDatabaseConfiguration configuration,
                                            com.couchbase.lite.internal.database.sqlite.SQLiteConnectionListener connectionListener) {
        if (configuration == null) {
            throw new IllegalArgumentException("configuration must not be null.");
        }

        // Create the pool.
        SQLiteConnectionPool pool = new SQLiteConnectionPool(configuration, connectionListener);
        pool.open(); // might throw
        return pool;
    }
810496
public Record openMainRecord()
    {
        Record record = Record.makeRecordFromClassName(MenusModel.THICK_CLASS, this);
        record.setOpenMode(DBConstants.OPEN_READ_ONLY);   // This will optimize the cache when client is remote.
        return record;
    }
607524
public Connection<T> createConnection()
    {
        //log info
        this.LOGGER.logInfo(new Object[]{"Opening a new connection from factory type: ",this.getClass().getName()},null);

        //create resource
        T resource=this.createResourceImpl();
        if(resource==null)
        {
            throw new FaxException("Unable to create resource.");
        }

        //create connection
        Connection<T> connection=this.createConnectionForResource(resource);

        //register connection
        CloseableResourceManager.registerCloseable(connection);

        //log info
        this.LOGGER.logInfo(new Object[]{"New connection opened."},null);
        
        return connection;
    }
996451
public static Connection getconnnection() {
		Connection con = null;
		try {
			con = DriverManager.getConnection(url, userName, password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}
340166
public Map<String, Integer> openConnections() {
	Map<String, Integer> map = new HashMap<String, Integer>();
	Iterator<DCStack> it = dcs.values().iterator();

	// all connections in pool
	DCStack dcstack;
	while (it.hasNext()) {
	    dcstack = it.next();
	    Integer val = map.get(dcstack.getDatasource().getName());
	    if (val == null) val = dcstack.openConnections();
	    else val = val.intValue() + dcstack.openConnections();
	    map.put(dcstack.getDatasource().getName(), val);
	}
	return map;
    }
747068
protected Connection<CommPortAdapter> getCommPortConnection()
    {
        Connection<CommPortAdapter> connection=null;
        synchronized(this)
        {
            boolean connectionValid=true;
            //if no connection available
            if(this.commConnection==null)
            {
                connectionValid=false;
            }
            else
            {
                //get adapter
                CommPortAdapter adapter=this.commConnection.getResource();

                //if current adapter is not valid/open
                if(!adapter.isOpen())
                {
                    connectionValid=false;
                }
            }
            
            if(!connectionValid)
            {
                //release old connection
                this.releaseCommPortConnection();

                //create new connection
                this.commConnection=this.createCommPortConnection();
            }
        }
            
        //get connection
        connection=this.commConnection;
        
        return connection;
    }
924591
private DBConn createAndConnectConn(String keyspace) throws DBNotAvailableException, RuntimeException {
        DBConn dbConn = new DBConn(this, keyspace);
        connectDBConn(dbConn);
        return dbConn;
    }
1318920
public Connection getConnection() throws FetchException {
        try {
            if (mOpenConnections == null) {
                throw new FetchException("Repository is closed");
            }

            JDBCTransaction txn = localTransactionScope().getTxn();
            if (txn != null) {
                // Return the connection used by the current transaction.
                return txn.getConnection();
            }

            // Get connection outside lock section since it may block.
            Connection con = mDataSource.getConnection();
            con.setAutoCommit(true);

            mOpenConnectionsLock.lock();
            try {
                if (mOpenConnections == null) {
                    con.close();
                    throw new FetchException("Repository is closed");
                }
                mOpenConnections.put(con, null);
            } finally {
                mOpenConnectionsLock.unlock();
            }

            return con;
        } catch (Exception e) {
            throw toFetchException(e);
        }
    }
1008027
public Connection getConnection() throws SQLException {
    try {
      if (pool == null) {
        initialize();
      }
      return pool.getConnection();
    } catch (SQLException e) {
      throw ExceptionMapper.getException(e, null, null, false);
    }
  }
400141
@Override
    protected Object openConnection() throws ConnectionException {
        qConnection = null;
        qSession = null;
        queue = null;
        try {
            String server_url = this.getAttributeValueSmart(SERVER_URL);
            if ("THIS_SERVER".equals(server_url)) server_url = null;
            String queue_name = this.getQueueName();
            JMSServices jmsServices = JMSServices.getInstance();
            QueueConnectionFactory qFactory = jmsServices.getQueueConnectionFactory(server_url);
            qConnection = qFactory.createQueueConnection();
            qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            qConnection.start();
            queue = jmsServices.getQueue(qSession, queue_name);
        } catch (Exception e) {
            logger.severeException("Exception in JmsAdapter.openConnection()" , e);
            throw new ConnectionException(ConnectionException.CONNECTION_DOWN, "Exception in invoking JmsAdapter" , e);

        }
        return qSession;
    }
1040057
@SuppressWarnings("resource")
	protected DatabaseConnection makeConnection(Logger logger) throws SQLException {
		Properties properties = new Properties();
		if (username != null) {
			properties.setProperty("user", username);
		}
		if (password != null) {
			properties.setProperty("password", password);
		}
		DatabaseConnection connection = new JdbcDatabaseConnection(DriverManager.getConnection(url, properties));
		// by default auto-commit is set to true
		connection.setAutoCommit(true);
		if (connectionProxyFactory != null) {
			connection = connectionProxyFactory.createProxy(connection);
		}
		logger.debug("opened connection to {} got #{}", url, connection.hashCode());
		return connection;
	}
811180
private boolean tryOpenAsync() {
        Connection<CL> connection = null;
        // Try to open a new connection, as long as we haven't reached the max
        if (activeCount.get() < config.getMaxConnsPerHost()) {
            try {
                if (activeCount.incrementAndGet() <= config.getMaxConnsPerHost()) {
                    // Don't try to open too many connections at the same time.
                    if (pendingConnections.incrementAndGet() > config.getMaxPendingConnectionsPerHost()) {
                        pendingConnections.decrementAndGet();
                    }
                    else {
                        try {
                            connectAttempt.incrementAndGet();
                            connection = factory.createConnection(this);
                            connection.openAsync(new Connection.AsyncOpenCallback<CL>() {
                                @Override
                                public void success(Connection<CL> connection) {
                                    openConnections.incrementAndGet();
                                    pendingConnections.decrementAndGet();
                                    availableConnections.add(connection);
    
                                    // Sanity check in case the connection
                                    // pool was closed
                                    if (isShutdown()) {
                                        discardIdleConnections();
                                    }
                                }
    
                                @Override
                                public void failure(Connection<CL> conn, ConnectionException e) {
                                    failedOpenConnections.incrementAndGet();
                                    pendingConnections.decrementAndGet();
                                    activeCount.decrementAndGet();
    
                                    if (e instanceof IsDeadConnectionException) {
                                        noteError(e);
                                    }
                                }
                            });
                            return true;
                        }
                        catch (ThrottledException e) {
                            // Trying to open way too many connections here
                        }
                        finally {
                            if (connection == null)
                                pendingConnections.decrementAndGet();
                        }
                    }
                }
            }
            finally {
                if (connection == null) {
                    activeCount.decrementAndGet();
                }
            }
        }
        return false;
    }
1073581
public Connection<A> createConnection(ConnectionData data) {
		return new OAuth1Connection<A>(data, getOAuth1ServiceProvider(), getApiAdapter());
	}
745219
Connection getSingleConnection() {
        Connection connection = null;
        try {
            Class.forName(driver);
            connection = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            throw new InitializationException("Could not initialize the connection", e);
        } catch (ClassNotFoundException e) {
            throw new InitializationException("Could not find the driver class", e);
        }
        return connection;
    }
288181
protected Connection openConnection() throws IOException {
        // Perhaps this can just be done once?
        CallbackHandler callbackHandler = null;
        SSLContext sslContext = null;
        if (realm != null) {
            sslContext = realm.getSSLContext();
            CallbackHandlerFactory handlerFactory = realm.getSecretCallbackHandlerFactory();
            if (handlerFactory != null) {
                String username = this.username != null ? this.username : localHostName;
                callbackHandler = handlerFactory.getCallbackHandler(username);
            }
        }
        final ProtocolConnectionConfiguration config = ProtocolConnectionConfiguration.copy(configuration);
        config.setCallbackHandler(callbackHandler);
        config.setSslContext(sslContext);
        config.setUri(uri);

        AuthenticationContext authenticationContext = this.authenticationContext != null ? this.authenticationContext : AuthenticationContext.captureCurrent();

        // Connect
        try {
            return authenticationContext.run((PrivilegedExceptionAction<Connection>) () -> ProtocolConnectionUtils.connectSync(config));
        } catch (PrivilegedActionException e) {
            if (e.getCause() instanceof IOException) {
                throw (IOException) e.getCause();
            }
            throw new IOException(e);
        }
    }