Choose better way to execute queries according to query and options.

@param size parameters number
@throws SQLException if any error occur
775222
private void executeInternalBatch(int size) throws SQLException {
    executeQueryPrologue(true);
    results = new Results(this, 0, true, size, false, resultSetScrollType,
            resultSetConcurrency, autoGeneratedKeys, protocol.getAutoIncrementIncrement());
    if (protocol
        .executeBatchClient(protocol.isMasterConnection(), results, prepareResult, parameterList,
            hasLongData)) {
      return;
    }

    //send query one by one, reading results for each query before sending another one
    SQLException exception = null;

    if (queryTimeout > 0) {
      for (int batchQueriesCount = 0; batchQueriesCount < size; batchQueriesCount++) {
        protocol.stopIfInterrupted();
        try {
          protocol.executeQuery(protocol.isMasterConnection(), results, prepareResult,
              parameterList.get(batchQueriesCount));
        } catch (SQLException e) {
          if (options.continueBatchOnError) {
            exception = e;
          } else {
            throw e;
          }
        }
      }

    } else {
      for (int batchQueriesCount = 0; batchQueriesCount < size; batchQueriesCount++) {
        try {
          protocol.executeQuery(protocol.isMasterConnection(), results, prepareResult,
              parameterList.get(batchQueriesCount));
        } catch (SQLException e) {
          if (options.continueBatchOnError) {
            exception = e;
          } else {
            throw e;
          }
        }
      }
    }
    if (exception != null) {
      throw exception;
    }

  }
775064
@Override
    public boolean execute() throws SQLException {
        boolean isOk = false;

        try {
            boolean result = internalStmt.execute();
            isOk = true;

            return result;
        } finally {
            poolableConn.updateLastSQLExecutionTime(isOk);
        }
    }
551129
public boolean execute() throws SQLException {
        boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
        SQLExecuteCallback<Boolean> executeCallback = SQLExecuteCallbackFactory.getPreparedSQLExecuteCallback(getDatabaseType(), isExceptionThrown);
        List<Boolean> result = executeCallback(executeCallback);
        if (null == result || result.isEmpty() || null == result.get(0)) {
            return false;
        }
        return result.get(0);
    }
249851
static ResultSet executeStatement(SQL sql) throws SQLException {
    try (SqlSession session = sqlSessionFactory.openSession(true)) {
      try (Connection conn = session.getConnection()) {
        try (Statement stmt = conn.createStatement()) {
          return stmt.executeQuery(sql.toString());
        }
      }
    }
  }
406940
private CommandOutput<?, ?> executePreparedSql(List<Command> cmds) {
    String query = null;
    List<String> queryParameters = null;
    int fetchSize = 0;

    for (Command cmd : cmds) {
      if (cmd instanceof JdbcCommand) {
        JdbcCommandType type = (JdbcCommandType) cmd.getCommandType();
        switch (type) {
          case QUERY:
            query = cmd.getParams().get(0);
            break;
          case QUERYPARAMS:
            queryParameters = cmd.getParams();
            break;
          case FETCHSIZE:
            fetchSize = Integer.parseInt(cmd.getParams().get(0));
            break;
          default:
            this.log.error("Command " + type.toString() + " not recognized");
            break;
        }
      }
    }

    this.log.info("Executing query:" + query);
    ResultSet resultSet = null;
    try {
      this.jdbcSource = createJdbcSource();
      if (this.dataConnection == null) {
        this.dataConnection = this.jdbcSource.getConnection();
      }

      PreparedStatement statement =
          this.dataConnection.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

      int parameterPosition = 1;
      if (queryParameters != null && queryParameters.size() > 0) {
        for (String parameter : queryParameters) {
          statement.setString(parameterPosition, parameter);
          parameterPosition++;
        }
      }
      if (fetchSize != 0) {
        statement.setFetchSize(fetchSize);
      }
      final boolean status = statement.execute();
      if (status == false) {
        this.log.error("Failed to execute sql:" + query);
      }
      resultSet = statement.getResultSet();

    } catch (Exception e) {
      this.log.error("Failed to execute sql:" + query + " ;error-" + e.getMessage(), e);
    }

    CommandOutput<JdbcCommand, ResultSet> output = new JdbcCommandOutput();
    output.put((JdbcCommand) cmds.get(0), resultSet);
    return output;
  }
35350
private void executeSQL(String sqlName, String tableName,
			String geometryColumnName) {
		executeSQL(sqlName, tableName, geometryColumnName, null);
	}
294174
public ResultSet executeQuery(final String query) throws SQLException {
        startTimer();
        try {
            if (queryResult != null) {
                queryResult.close();
            }
            final Query queryToSend = queryFactory.createQuery(query);
            queryResult = protocol.executeQuery(queryToSend);
            warningsCleared = false;
            return new DrizzleResultSet(queryResult, this, getProtocol());
        } catch (QueryException e) {
            throw SQLExceptionMapper.get(e);
        } finally {
            stopTimer();
        }
    }
488235
private void executeSql(final Connection connection, final String sql, final boolean isCommit) throws SQLException
   {
      if (sql != null) {
         try (Statement statement = connection.createStatement()) {
            // connection was created a few milliseconds before, so set query timeout is omitted (we assume it will succeed)
            statement.execute(sql);
         }

         if (isIsolateInternalQueries && !isAutoCommit) {
            if (isCommit) {
               connection.commit();
            }
            else {
               connection.rollback();
            }
         }
      }
   }
232005
public SQLException exceptionWithQuery(SQLException sqlEx, PrepareResult prepareResult) {
    if (options.dumpQueriesOnException || sqlEx.getErrorCode() == 1064) {
      String querySql = prepareResult.getSql();
      String message = sqlEx.getMessage();
      if (options.maxQuerySizeToLog != 0 && querySql.length() > options.maxQuerySizeToLog - 3) {
        message += "\nQuery is: " + querySql.substring(0, options.maxQuerySizeToLog - 3) + "...";
      } else {
        message += "\nQuery is: " + querySql;
      }
      message += "\njava thread: " + Thread.currentThread().getName();
      return new SQLException(message, sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getCause());
    }
    return sqlEx;
  }
120443
@Override
	public final boolean execute() throws SQLException {
		Split split = prepare();
		try {
			return stmt.execute();
		} finally {
			finish(split);
		}
	}
263356
private String exWithQuery(String message, PrepareResult serverPrepareResult,
      ParameterHolder[] parameters) {
    if (options.dumpQueriesOnException) {
      StringBuilder sql = new StringBuilder(serverPrepareResult.getSql());
      if (serverPrepareResult.getParamCount() > 0) {
        sql.append(", parameters [");
        if (parameters.length > 0) {
          for (int i = 0; i < Math.min(parameters.length, serverPrepareResult.getParamCount());
              i++) {
            sql.append(parameters[i].toString()).append(",");
          }
          sql = new StringBuilder(sql.substring(0, sql.length() - 1));
        }
        sql.append("]");
      }

      if (options.maxQuerySizeToLog != 0 && sql.length() > options.maxQuerySizeToLog - 3) {
        return message
            + "\nQuery is: " + sql.substring(0, options.maxQuerySizeToLog - 3) + "..."
            + "\njava thread: " + Thread.currentThread().getName();
      } else {
        return message
            + "\nQuery is: " + sql
            + "\njava thread: " + Thread.currentThread().getName();
      }
    }
    return message;
  }
1230361
public ResultSet executeQuery(String sql) throws SQLException {
    if (executeInternal(sql, fetchSize, Statement.NO_GENERATED_KEYS)) {
      return results.getResultSet();
    }
    return SelectResultSet.createEmptyResultSet();
  }
248665
public void setNeedleSize(final NeedleSize SIZE) {
        if (null == needleSize) {
            _needleSize = null == SIZE ? NeedleSize.STANDARD : SIZE;
            fireUpdateEvent(RESIZE_EVENT);
        } else {
            needleSize.set(SIZE);
        }
    }
534723
public int execute(String sql, Object... params) throws SQLException {
		Connection conn = null;
		try {
			conn = this.getConnection();
			return SqlExecutor.execute(conn, sql, params);
		} catch (SQLException e) {
			throw e;
		} finally {
			this.closeConnection(conn);
		}
	}
671890
public static int execute(Connection conn, String sql, Object... params) throws SQLException {
		PreparedStatement ps = null;
		try {
			ps = StatementUtil.prepareStatement(conn, sql, params);
			return ps.executeUpdate();
		} finally {
			DbUtil.close(ps);
		}
	}
559705
public final void execute()
  {
    _log.debug( _sqlString );

    CallableStatement lCallableStatement = null;

    try
    {
      lCallableStatement = _callableStatementProvider.createCallableStatement( _sqlString );

      useCallableStatement( lCallableStatement );
    }
    catch( SQLException e )
    {
      _log.debug( e + ": " + _sqlString, e );

      throw ExceptionManager.createException( e, _sqlString );
    }
    finally
    {
      if( lCallableStatement != null )
      {
        try
        {
          lCallableStatement.close();
        }
        catch( SQLException e )
        {
          _log.debug( e, e );

          throw ExceptionManager.createException( e, _sqlString );
        }
      }
    }
  }
1047928
public int execute(String sql, Object... params) {
        Connection conn = getConn();
        try {
            return conn.createQuery(sql)
                    .withParams(params)
                    .executeUpdate()
                    .getResult();
        } finally {
            this.closeConn(conn);
            this.clean(conn);
        }
    }