Sends given query to BE to start, initialize and lock connection for a CopyOperation.

@param sql COPY FROM STDIN / COPY TO STDOUT statement
@return CopyIn or CopyOut operation object
@throws SQLException on failure
431253
public synchronized CopyOperation startCopy(String sql, boolean suppressBegin)
      throws SQLException {
    waitOnLock();
    if (!suppressBegin) {
      doSubprotocolBegin();
    }
    byte[] buf = Utils.encodeUTF8(sql);

    try {
      LOGGER.log(Level.FINEST, " FE=> Query(CopyStart)");

      pgStream.sendChar('Q');
      pgStream.sendInteger4(buf.length + 4 + 1);
      pgStream.send(buf);
      pgStream.sendChar(0);
      pgStream.flush();

      return processCopyResults(null, true);
      // expect a CopyInResponse or CopyOutResponse to our query above
    } catch (IOException ioe) {
      throw new PSQLException(GT.tr("Database connection failed when starting copy"),
          PSQLState.CONNECTION_FAILURE, ioe);
    }
  }
272138
public void runSql( String sql ) throws Exception {
        String[] sqlSplit = sql.split("\n");
        StringBuilder sb = new StringBuilder();
        for( String string : sqlSplit ) {
            String trim = string.trim();
            if (trim.length() == 0) {
                continue;
            }
            if (trim.startsWith("--")) {
                continue;
            }
            sb.append(trim + " ");
        }

        String[] sqls = sb.toString().split(";");
        for( String single : sqls ) {
            executeInsertUpdateDeleteSql(single);
        }
    }
506969
public static int update(String sql, Object... args) {
		int result = 0;
		Connection con = getconnnection();
		PreparedStatement ps = null;
		try {
			ps = con.prepareStatement(sql);
			if (args != null) {
				for (int i = 0; i < args.length; i++) {
					ps.setObject((i + 1), args[i]);
				}
			}
			result = ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(ps, con);
		}

		return result;
	}
1060113
def execute(self, sql, parameters = None, cursorClass = DictCursor, quiet = False, locked = False, do_commit = True):
		""""""
		i = 0
		errcode = 0
		caughte = None
		cursor = None
		if sql.find(";") != -1 or sql.find("\\G") != -1:
			# Catches some injections
			raise Exception("The SQL command '%s' contains a semi-colon or \\G. This is a potential SQL injection." % sql)
		while i < self.numTries:
			i += 1
			try:
				assert(not(self.connection) or not(self.connection.open))
				self._get_connection(cursorClass)
				cursor = self.connection.cursor()
				if locked:
					cursor.execute(self.lockstring)
					self.locked = True
				if parameters:
					errcode = cursor.execute(sql, parameters)
				else:
					errcode = cursor.execute(sql)
				self.lastrowid = int(cursor.lastrowid)
				if do_commit and self.isInnoDB:
					self.connection.commit()
				results = cursor.fetchall()
				if locked:
					cursor.execute(self.unlockstring)
					self.locked = False
				cursor.close()
				self._close_connection()
				return results
			except MySQLdb.OperationalError, e:
				if cursor:
					if self.locked:
						cursor.execute(self.unlockstring)
						self.locked = False
					cursor.close()
				self._close_connection()
				caughte = str(e)
				errcode = e[0]
				continue
			except Exception, e:
				if cursor:
					if self.locked:
						cursor.execute(self.unlockstring)
						self.locked = False
					cursor.close()
				self._close_connection()
				caughte = str(e)
				traceback.print_exc()
				break
			sleep(0.2)
		
		if not quiet:
			sys.stderr.write("\nSQL execution error in query %s at %s:" % (sql, datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
			sys.stderr.write("\nErrorcode/Error: %d - '%s'.\n" % (errcode, str(caughte)))
			sys.stderr.flush()
		raise MySQLdb.OperationalError(caughte)
1193243
public static void execSQL(Connection connection, String sql) {
		Statement statement = null;
		try {
			statement = connection.createStatement();
			statement.execute(sql);
		} catch (SQLException e) {
			throw new GeoPackageException("Failed to execute SQL statement: "
					+ sql, e);
		} finally {
			closeStatement(statement, sql);
		}

	}
1230361
public ResultSet executeQuery(String sql) throws SQLException {
    if (executeInternal(sql, fetchSize, Statement.NO_GENERATED_KEYS)) {
      return results.getResultSet();
    }
    return SelectResultSet.createEmptyResultSet();
  }
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());
        }
      }
    }
  }
862842
protected void init(Source source) throws SQLException {

        if (source == null) {
            throw Util.nullArgument("source");
        }

        Transformer           transformer =
            JDBCSQLXML.getIdentityTransformer();
        StreamResult          result      = new StreamResult();
        ByteArrayOutputStream baos        = new ByteArrayOutputStream();
        GZIPOutputStream      gzos;

        try {
            gzos = new GZIPOutputStream(baos);
        } catch (IOException ex) {
            throw Exceptions.transformFailed(ex);
        }
        result.setOutputStream(gzos);

        try {
            transformer.transform(source, result);
        } catch (TransformerException ex) {
            throw Exceptions.transformFailed(ex);
        }

        try {
            gzos.close();
        } catch (IOException ex) {
            throw Exceptions.transformFailed(ex);
        }

        byte[] data = baos.toByteArray();

        setGZipData(data);
        setReadable(true);
        setWritable(false);
    }
406037
public synchronized QueryResult execute() throws QueryException, InterruptedException {
		// create query string
		String queryString = createQueryString();

        PreparedStatement countPstmt = null;
        if (computeCount) {
            try {
                // count statement
                String countQueryString = "SELECT COUNT(*) FROM (" + queryString + ") A";
                if (isCsv) {
                	// csv jdbc driver does not support sub-select
                	countQueryString = getCsvCountQuery(queryString);
                }
                countPstmt = createStatement(countQueryString);
                if (parameterNames.size() != 0) {
                    setParameterValues(countPstmt);
                }
            } catch (QueryException ex) {
                LOG.info("Cannot create count statement : " + ex.getMessage() + " .Will use rs.last()");
                countPstmt = null;
            }
        }

        // create statement
		PreparedStatement pstmt = createStatement(queryString);

        // set parameter values
		if (parameterNames.size() != 0) {
			setParameterValues(pstmt);
		}
        
        try {
            setOutParametersValues(pstmt);
        } catch (SQLException e) {
            throw new QueryException(e);
        } catch (DialectException e) {
            throw new QueryException("Error set out parameter values for executing query : could not get dialect", e);
        }

        // set query's input wrapper
		synchronized (inputWrapper) {
			inputWrapper.statement = pstmt;
            inputWrapper.countStatement = countPstmt;
            inputWrapper.query = queryString;
			inputWrapper.pending = true;
			inputWrapper.notify();
		}

		synchronized (resultWrapper) {
			try {
				// wait for the query to complete
				while (!resultWrapper.serviced) {
					resultWrapper.wait();
				}
				if (resultWrapper.exception != null) {
					throw resultWrapper.exception;
				}
			} catch (InterruptedException e) {
				cancel();
				throw e;
			} finally {
				resultWrapper.serviced = false;
			}

			if ((maxRows > 0) && (resultWrapper.count > maxRows)) {
				resultWrapper.count = maxRows;
			}

			//must finish run method thread normally
			closeRequest = true;
			synchronized (inputWrapper) {
				inputWrapper.pending = true;
				inputWrapper.notify();
			}

			return new QueryResult(resultWrapper.resultSet, resultWrapper.count, resultWrapper.executeTime);
		}
	}
903473
public void doSQL(final String sql) throws SQLException {

		LOG.info("Connecting to: " + this.dbString + " with " + this.usr
				+ " and " + this.pwd);
		LOG.info("Running: " + sql);
		Connection connection = null;
		Statement st = null;

		try {
			connection = DriverManager.getConnection(this.dbString, this.usr,
					this.pwd);

			st = connection.createStatement();
			st.executeUpdate(sql);

		} finally {

			if (st != null) {
				st.close();
			}
			if (connection != null) {
				connection.close();
			}
		}

	}
1316803
public void executeQuery(String query, Optional<String> proxy)
      throws SQLException {
    executeQueries(Collections.singletonList(query), proxy);
  }
230698
public SQLException exceptionWithQuery(String sql, SQLException sqlException,
      boolean explicitClosed) {
    if (explicitClosed) {
      return new SQLException(
          "Connection has explicitly been closed/aborted.\nQuery is: " + subQuery(sql),
          sqlException.getSQLState(),
          sqlException.getErrorCode(), sqlException.getCause());
    }

    if (options.dumpQueriesOnException || sqlException.getErrorCode() == 1064) {
      return new SQLException(sqlException.getMessage()
          + "\nQuery is: " + subQuery(sql)
          + "\njava thread: " + Thread.currentThread().getName(),
          sqlException.getSQLState(),
          sqlException.getErrorCode(), sqlException.getCause());
    }
    return sqlException;
  }
1013917
@Override
    public ResultSet executeQuery(String sql) throws SQLException {
        boolean isOk = false;

        try {
            final ResultSet result = wrap(internalStmt.executeQuery(sql));
            isOk = true;
            return result;
        } finally {
            poolableConn.updateLastSQLExecutionTime(isOk);
        }
    }
1092345
public static int executeUpdate(final String sql, final Object... args)
    {
       return SqlClosure.sqlExecute(c -> executeUpdate(c, sql, args));
    }
1129089
public static boolean startTransaction(Connection conn) throws SQLException {
        if (conn == null) {
            return false;
        }
        String dsName = openConnDsName.get().get(conn);
        OpenConnStats connStats = dsName != null ? openConnStats.get().get(dsName) : null;
        if (connStats != null && !connStats.inTransaction) {
            conn.setAutoCommit(false);
            connStats.inTransaction = true;
            return true;
        }
        return false;
    }
408566
public synchronized QueryResult execute() throws QueryException, InterruptedException {
        // create query string
        String queryString = query.getText();
        System.out.println("queryString = " + queryString);

        // count statement
        String countQueryString = "SELECT COUNT(*) FROM (" + queryString + ")";


        // set query's input wrapper
        synchronized (inputWrapper) {
            try {
                inputWrapper.statement = conn.createStatement();
            } catch (SQLException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                return null;
            }
            inputWrapper.query = queryString;
            try {
                inputWrapper.countStatement = conn.createStatement();
            } catch (SQLException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                return null;
            }
            inputWrapper.countQuery = countQueryString;
            inputWrapper.pending = true;
            inputWrapper.notify();
        }

        synchronized (resultWrapper) {
            try {
                // wait for the query to complete
                while (!resultWrapper.serviced) {
                    resultWrapper.wait();
                }
                if (resultWrapper.exception != null) {
                    throw resultWrapper.exception;
                }
            } catch (InterruptedException e) {
                cancel();
                throw e;
            } finally {
                resultWrapper.serviced = false;
            }

            return new QueryResult(resultWrapper.resultSet, resultWrapper.count, resultWrapper.executeTime);
        }
    }
215714
@Deprecated
	public static ResultSet query(String sql, Object... args) {
		ResultSet result = null;
		Connection con = getconnnection();
		PreparedStatement ps = null;
		try {
			ps = con.prepareStatement(sql);
			if (args != null) {
				for (int i = 0; i < args.length; i++) {
					ps.setObject((i + 1), args[i]);
				}
			}
			result = ps.executeQuery();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}