从指定的逻辑数据库源中获取数据库连接。
@param source
@return the database connection
@throws SQLException
518249
public static Connection getConnection(String source) throws SQLException {
		DataSource ds = getDataSource(source);
		if (ds == null){
			throw new SQLException("ConnectionUtility cannot get data source: " + source);
		}
		return ds.getConnection();
	}
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;
		}
	}
135423
Connection getConnection() throws SQLException {
		if (connection == null) {
			connection = connectionSupplier.getConnection();
			initSavepoints(connection);
		}
		return connection;
	}
808616
public Object sqlToJava(Object source)
    {
        try
        {
            ByteArrayInputStream stringIn =
                new ByteArrayInputStream(((String) source).getBytes());
            Base64.InputStream uuIn =
                new Base64.InputStream(stringIn, Base64.DECODE, false);
            GZIPInputStream gzipIn = new GZIPInputStream(uuIn);
            ObjectInputStream objIn = new ObjectInputStream(gzipIn);
            Object result = objIn.readObject();

            objIn.close();
            return result;
        }
        catch (Throwable t)
        {
            throw new ConversionException(t);
        }
    }
140787
public XAConnection getXAConnection() throws SQLException {

        // Comment out before public release:
        System.err.print("Executing " + getClass().getName()
                         + ".getXAConnection()...");

        try {
            Class.forName(driver).newInstance();
        } catch (ClassNotFoundException e) {
            throw new SQLException("Error opening connection: "
                                   + e.getMessage());
        } catch (IllegalAccessException e) {
            throw new SQLException("Error opening connection: "
                                   + e.getMessage());
        } catch (InstantiationException e) {
            throw new SQLException("Error opening connection: "
                                   + e.getMessage());
        }

        JDBCConnection connection =
            (JDBCConnection) DriverManager.getConnection(url, connProperties);

        // Comment out before public release:
        System.err.print("New phys:  " + connection);

        JDBCXAResource xaResource = new JDBCXAResource(connection, this);
        JDBCXAConnectionWrapper xaWrapper =
            new JDBCXAConnectionWrapper(connection, xaResource,
                                        connectionDefaults);
        JDBCXAConnection xaConnection = new JDBCXAConnection(xaWrapper,
            xaResource);

        xaWrapper.setPooledConnection(xaConnection);

        return xaConnection;
    }
379710
private Connection getConnection() throws JspException, SQLException {
	// Fix: Add all other mechanisms
	Connection conn = null;
	isPartOfTransaction = false;

        TransactionTagSupport parent = (TransactionTagSupport)
	    findAncestorWithClass(this, TransactionTagSupport.class);
	if (parent != null) {
            if (dataSourceSpecified) {
                throw new JspTagException(
                    Resources.getMessage("ERROR_NESTED_DATASOURCE"));
            }
	    conn = parent.getSharedConnection();
            isPartOfTransaction = true;
	} else {
	    if ((rawDataSource == null) && dataSourceSpecified) {
		throw new JspException(
		    Resources.getMessage("SQL_DATASOURCE_NULL"));
	    }
	    DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource,
								 pageContext);
            try {
                conn = dataSource.getConnection();
            } catch (Exception ex) {
                throw new JspException(
                    Resources.getMessage("DATASOURCE_INVALID",
					 ex.toString()));
            }
	}

	return conn;
    }
96369
public final Connection getConnection() throws SQLException {

      final Timer.Context ctx = acquisitions.time();

      try {

         Connection conn;
         for(int i = 0; i < activeSegments; i++) {
            conn = segments[i].open();
            if(conn != null) {
               return conn;
            }
         }

         //All connections for active segments were in-use.
         //Send signal to attempt to activate a new segment then
         //try the active segments in-order (again) with the acquire time-out.

         signalActivateSegment();

         try {

            for(int i = 0; i < activeSegments; i++) {
               ConnectionPoolSegment segment = segments[i];
               conn = segment.open(segment.acquireTimeoutMillis, TimeUnit.MILLISECONDS);
               if(conn != null) {
                  return conn;
               }
            }

         } catch(InterruptedException ie) {
            Thread.currentThread().interrupt();
            throw new SQLException("Connection pool, '" + name + "' interrupted during acquire", JDBConnection.SQLSTATE_CONNECTION_EXCEPTION);
         }

         //Try all pools again with maximum acquire timeout.

         long maxTimeoutMillis = saturatedAcquireTimeoutMillis / activeSegments;

         try {

            for(int i = 0; i < activeSegments; i++) {
               ConnectionPoolSegment segment = segments[i];
               conn = segment.open(maxTimeoutMillis, TimeUnit.MILLISECONDS);
               if(conn != null) {
                  return conn;
               }
            }

         } catch(InterruptedException ie) {
            Thread.currentThread().interrupt();
            throw new SQLException("Connection pool, '" + name + "' interrupted during acquire", JDBConnection.SQLSTATE_CONNECTION_EXCEPTION);
         }

         //Done trying

         failedAcquisitions.mark();

         throw new SQLException(SATURATED_MESSAGE, JDBConnection.SQLSTATE_CONNECTION_FAILURE);

      } finally {
         ctx.stop();
      }
   }
1030901
public Connection getConnection() throws SQLException {
    try {
      if (urlParser == null) {
        initialize();
      }

      return MariaDbConnection.newConnection(urlParser, null);
    } catch (SQLException e) {
      throw ExceptionMapper.getException(e, null, null, false);
    }
  }
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);
    }
530873
public Connection getConnection(String username, String password)
	throws SQLException {
		try {
			return this.multiDataSource.get(new UsernamePassword(username, password)).getConnection();
		} catch (ExecutionException e) {
			throw PoolUtil.generateSQLException("Unable to obtain connection", e);

		}
	}
137736
protected Connection getConnectionInternal(Properties info) throws SQLException {
    if (url == null) {
      throw new SQLException(Message.DOMAGEN5002.getMessage());
    }
    try {
      return DriverManager.getConnection(url, info);
    } catch (SQLException e) {
      if (UNABLE_TO_ESTABLISH_CONNECTION.equals(e.getSQLState())) {
        throw new SQLException(Message.DOMAGEN5001.getMessage(), UNABLE_TO_ESTABLISH_CONNECTION, e);
      }
      throw e;
    }
  }
820676
@Override
	public Connection getConnection(final String datasourceName) {
		try {
			DataSource ds = dsMap.computeIfAbsent(datasourceName, DataSourceConnectionSupplierImpl::getNewDataSource);
			final Connection connection;
			synchronized (ds) {
				connection = ds.getConnection();
			}
			boolean autoCommit = getAutoCommit(datasourceName);
			if (connection.getAutoCommit() != autoCommit) {
				connection.setAutoCommit(autoCommit);
			}
			boolean readOnly = getReadOnly(datasourceName);
			if (connection.isReadOnly() != readOnly) {
				connection.setReadOnly(readOnly);
			}
			int transactionIsolation = getTransactionIsolation(datasourceName);
			if (transactionIsolation > 0 && connection.getTransactionIsolation() != transactionIsolation) {
				connection.setTransactionIsolation(transactionIsolation);
			}
			return connection;
		} catch (SQLException ex) {
			throw new UroborosqlRuntimeException("Connection[" + datasourceName + "] can not be acquired.", ex);
		}
	}
850822
public boolean setupDirectDataSourceConnection() throws DBException
    {
        if (m_JDBCConnection != null)
            return true;
        try {
            if (m_datasourceFactory == null)
            {
                String strClassName = this.getProperty(SQLParams.DATASOURCE_FACTORY);
            	strClassName = ClassServiceUtility.getFullClassName(strClassName);
                try {
                	m_datasourceFactory = (DatasourceFactory)ClassServiceUtility.getClassService().makeObjectFromClassName(strClassName);
             	    //xClass<?> c = Class.forName(strClassName);
             	    //xm_datasourceFactory = (DatasourceFactory)c.newInstance();
                } catch (Exception e) {
            		Utility.getLogger().warning("Error on create class: " + strClassName);
            		e.printStackTrace();
                }
            }
            if (m_datasourceFactory == null)
                return false;   // No factory
            ConnectionPoolDataSource poolDataSource = m_datasourceFactory.getPooledDataSource(this);
            if (poolDataSource != null)
            	if (poolDataSource.getPooledConnection() != null)
            		m_JDBCConnection = poolDataSource.getPooledConnection().getConnection();
            if (m_JDBCConnection == null)
            {   // Otherwise, just try plain datasource connection
                DataSource dataSource = m_datasourceFactory.getFakePooledDataSource(this);
                if (dataSource != null)
                    m_JDBCConnection = dataSource.getConnection();
            }
            if (m_JDBCConnection == null)
            {   // Otherwise, just try plain datasource connection
                DataSource dataSource = m_datasourceFactory.getDataSource(this);
                if (dataSource != null)
                    m_JDBCConnection = dataSource.getConnection();
                else
                    return false;   // Failure
            }
        } catch (SQLException e) {
            return false;   // Failure
        }
        return true;    // Success!
    }
649516
public static void execute(final Connection connection, final String sql) throws SQLException {
        try (PreparedStatement preparedStatement = connection.prepareStatement(sql)){
            preparedStatement.execute();
        }
    }
156601
public static <T> DatabaseTableConfig<T> fromClass(ConnectionSource connectionSource, Class<T> clazz)
			throws SQLException {
		DatabaseType databaseType = connectionSource.getDatabaseType();
		String tableName = DatabaseTableConfig.extractTableName(databaseType, clazz);
		List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
		for (Class<?> classWalk = clazz; classWalk != null; classWalk = classWalk.getSuperclass()) {
			for (Field field : classWalk.getDeclaredFields()) {
				DatabaseFieldConfig config = configFromField(databaseType, tableName, field);
				if (config != null && config.isPersisted()) {
					fieldConfigs.add(config);
				}
			}
		}
		if (fieldConfigs.size() == 0) {
			return null;
		} else {
			return new DatabaseTableConfig<T>(clazz, tableName, fieldConfigs);
		}
	}
342563
@Override
    public Connection connect( String url,
                               Properties info ) throws SQLException {
        if (!acceptsURL(url)) {
            return null;
        }
        RepositoryDelegate repositoryDelegate = delegateFactory.createRepositoryDelegate(url, info, this.contextFactory);
        return repositoryDelegate.createConnection(getDriverInfo());
    }
919860
public Set<String> execute(final ConnectionResource _con)
        throws SQLException
    {
        final Set<String> ret = new HashSet<>();
        if (getIds().length > 1 || checkUpdateRequired(_con)) {
            final StringBuilder cmd = new StringBuilder()
                .append(Context.getDbType().getSQLPart(SQLPart.UPDATE)).append(" ")
                .append(Context.getDbType().getTableQuote())
                .append(getTableName())
                .append(Context.getDbType().getTableQuote()).append(" ")
                .append(Context.getDbType().getSQLPart(SQLPart.SET)).append(" ");

            // append SQL values
            boolean first = true;
            for (final ColumnWithSQLValue col : getColumnWithSQLValues())  {
                if (first)  {
                    first = false;
                } else  {
                    cmd.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
                }
                cmd.append(Context.getDbType().getColumnQuote())
                    .append(col.getColumnName())
                    .append(Context.getDbType().getColumnQuote())
                    .append(Context.getDbType().getSQLPart(SQLPart.EQUAL))
                    .append(col.getSqlValue());
            }

            // append values
            for (final AbstractColumnWithValue<?> col : getColumnWithValues())  {
                if (first)  {
                    first = false;
                } else  {
                    cmd.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
                }
                cmd.append(Context.getDbType().getColumnQuote())
                    .append(col.getColumnName())
                    .append(Context.getDbType().getColumnQuote())
                    .append(Context.getDbType().getSQLPart(SQLPart.EQUAL))
                    .append("?");
                ret.add(col.getColumnName());
            }

            // append where clause
            cmd.append(" ").append(Context.getDbType().getSQLPart(SQLPart.WHERE)).append(" ")
                .append(Context.getDbType().getColumnQuote())
                .append(getIdColumn())
                .append(Context.getDbType().getColumnQuote());

            if (this.ids.length == 1) {
                cmd.append(Context.getDbType().getSQLPart(SQLPart.EQUAL))
                    .append("?");
            } else {
                cmd.append(" ").append(Context.getDbType().getSQLPart(SQLPart.IN)).append(" ")
                    .append(Context.getDbType().getSQLPart(SQLPart.PARENTHESIS_OPEN));
                first = true;
                for (@SuppressWarnings("unused") final long id : this.ids) {
                    if (first)  {
                        first = false;
                    } else  {
                        cmd.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
                    }
                    cmd.append("?");
                }
                cmd.append(Context.getDbType().getSQLPart(SQLPart.PARENTHESIS_CLOSE));
            }

            if (SQLUpdate.LOG.isDebugEnabled()) {
                SQLUpdate.LOG.debug(cmd.toString());
            }

            final PreparedStatement stmt = _con.prepareStatement(cmd.toString());
            int index = 1;
            for (final AbstractColumnWithValue<?> col : getColumnWithValues())  {
                if (SQLUpdate.LOG.isDebugEnabled()) {
                    SQLUpdate.LOG.debug("    " + index + " = " + col.getValue());
                }
                col.set(index++, stmt);
            }

            for (final long id : this.ids) {
                SQLUpdate.LOG.debug("    " + index + " = " + id);
                stmt.setLong(index++, id);
            }

            try  {
                final int rows = stmt.executeUpdate();
                if (rows == 0) {
                    throw new SQLException("Object for SQL table '" + getTableName()
                            + "' with ids '" + this.ids + "' does not exists and was not updated.");
                }
            } finally  {
                stmt.close();
            }
        }
        return ret;
    }