ステートメント初期化。

@param sqlContext SQLコンテキスト
@return PreparedStatement
@throws SQLException SQL例外
187306
protected PreparedStatement getPreparedStatement(final SqlContext sqlContext) throws SQLException {
		PreparedStatement stmt = ((LocalTransactionManager) transactionManager).getPreparedStatement(sqlContext);
		// プロパティ設定
		applyProperties(stmt);
		return stmt;
	}
75268
public static SQLiteStatement compile(SQLContext context, String sql) {
		SQLiteStatement ps = context.database().compileStatement(sql);
		
		return ps;
	}
147474
public String prepareStatementString() throws SQLException {
		List<ArgumentHolder> argList = new ArrayList<ArgumentHolder>();
		return buildStatementString(argList);
	}
128025
@Override
	public int doUpdate(final SqlContext sqlContext, final PreparedStatement preparedStatement, final int result) {
		LOG.debug("SQL:{} executed. Count:{} items.", sqlContext.getSqlName(), result);
		return result;
	}
935059
public static PreparedStatement prepareStatementForBatch(Connection conn, String sql, Iterable<Object[]> paramsBatch) throws SQLException {
		Assert.notBlank(sql, "Sql String must be not blank!");

		sql = sql.trim();
		SqlLog.INSTASNCE.log(sql, paramsBatch);
		PreparedStatement ps = conn.prepareStatement(sql);
		for (Object[] params : paramsBatch) {
			StatementUtil.fillParams(ps, params);
			ps.addBatch();
		}
		return ps;
	}
1367087
@Override
	public Map<String, Object> procedure(final SqlContext sqlContext) throws SQLException {
		// パラメータログを出力する
		MDC.put(SUPPRESS_PARAMETER_LOG_OUTPUT, Boolean.FALSE.toString());

		// procedureやfunctionの場合、SQL文法エラーになるためバインドパラメータコメントを出力しない
		sqlContext.contextAttrs().put(CTX_ATTR_KEY_OUTPUT_BIND_COMMENT, false);

		// コンテキスト変換
		transformContext(sqlContext, false);

		StopWatch watch = null;

		try (CallableStatement callableStatement = getCallableStatement(sqlContext)) {

			// パラメータ設定
			sqlContext.bindParams(callableStatement);

			if (LOG.isDebugEnabled()) {
				LOG.debug("Execute stored procedure.");
				watch = new StopWatch();
				watch.start();
			}

			beforeProcedure(sqlContext);

			// デフォルト最大リトライ回数を取得し、個別指定（SqlContextの値）があれば上書き
			int maxRetryCount = getMaxRetryCount();
			if (sqlContext.getMaxRetryCount() > 0) {
				maxRetryCount = sqlContext.getMaxRetryCount();
			}

			// デフォルトリトライ待機時間を取得し、個別指定（SqlContextの値）があれば上書き
			int retryWaitTime = getRetryWaitTime();
			if (sqlContext.getRetryWaitTime() > 0) {
				retryWaitTime = sqlContext.getRetryWaitTime();
			}
			int loopCount = 0;
			do {
				try {
					if (maxRetryCount > 0 && getSqlConfig().getDialect().isRollbackToSavepointBeforeRetry()) {
						setSavepoint(RETRY_SAVEPOINT_NAME);
					}
					getSqlFilterManager().doProcedure(sqlContext, callableStatement, callableStatement.execute());
					break;
				} catch (SQLException ex) {
					if (maxRetryCount > 0 && getSqlConfig().getDialect().isRollbackToSavepointBeforeRetry()) {
						rollback(RETRY_SAVEPOINT_NAME);
					}
					if (maxRetryCount > loopCount) {
						String errorCode = String.valueOf(ex.getErrorCode());
						String sqlState = ex.getSQLState();
						if (getSqlRetryCodes().contains(errorCode) || getSqlRetryCodes().contains(sqlState)) {
							if (LOG.isDebugEnabled()) {
								LOG.debug(String.format(
										"Caught the error code to be retried.(%d times). Retry after %,3d ms.",
										loopCount + 1, retryWaitTime));
							}
							if (retryWaitTime > 0) {
								try {
									Thread.sleep(retryWaitTime);
								} catch (InterruptedException ie) {
									// do nothing
								}
							}
						} else {
							throw ex;
						}
					} else {
						throw ex;
					}
				} finally {
					if (maxRetryCount > 0 && getSqlConfig().getDialect().isRollbackToSavepointBeforeRetry()) {
						releaseSavepoint(RETRY_SAVEPOINT_NAME);
					}
					sqlContext.contextAttrs().put(CTX_ATTR_KEY_RETRY_COUNT, loopCount);
				}
			} while (maxRetryCount > loopCount++);
			// 結果取得
			return sqlContext.getOutParams(callableStatement);
		} catch (SQLException ex) {
			handleException(sqlContext, ex);
		} finally {
			afterProcedure(sqlContext);
			if (LOG.isDebugEnabled() && watch != null) {
				watch.stop();
				LOG.debug("Stored procedure execution time [{}] : [{}]", sqlContext.getSqlName(), watch.toString());
			}
			MDC.remove(SUPPRESS_PARAMETER_LOG_OUTPUT);
		}
		return null;
	}
785469
public Statement getPreparedStatement(String sql,
			Object[] parameters, boolean returnValues) throws DatabaseException {
		Statement stmt = null;
		try {
			if(supportPreparedStatement()){
				if (appendReturningColumnClause() && returnValues) {
					stmt = connection.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
				} else {
					stmt = connection.prepareStatement(sql);
				}
				if (parameters != null) {
					for (int i = 0; i < parameters.length; i++) {
						((PreparedStatement)stmt).setObject(i + 1,getEquivalentDBObject(parameters[i]));
					}
				}
			}else{//no substition of parameters
				stmt = connection.createStatement();
				return stmt;
			}
		} catch (SQLException e) {
			logSQL(stmt, sql, parameters, true);
			e.printStackTrace();
			throw new DataEntryException(e.getMessage());
		}
		return stmt;
	}
912486
@Override
    public void set(BindingSetStatementContext<JsonArray> ctx) throws SQLException {
        ctx.statement().setString(ctx.index(), Objects.toString(ctx.convert(converter()).value(), null));
    }
347456
public PreparedStatement getPreparedStatement(ClassDescriptor cds, String sql,
                                                  boolean scrollable, int explicitFetchSizeHint, boolean callableStmt)
            throws PersistenceBrokerException
    {
        try
        {
            return cds.getStatementsForClass(m_conMan).getPreparedStmt(m_conMan.getConnection(), sql, scrollable, explicitFetchSizeHint, callableStmt);
        }
        catch (LookupException e)
        {
            throw new PersistenceBrokerException("Used ConnectionManager instance could not obtain a connection", e);
        }
    }
974644
private void prepareStatements() throws DatabaseException {
        for (PreparedStatementCveDb key : values()) {
            PreparedStatement preparedStatement = null;
            try {
                final String statementString = statementBundle.getString(key.name());
                if (key == INSERT_VULNERABILITY || key == INSERT_CPE) {
                    preparedStatement = connection.prepareStatement(statementString, new String[]{"id"});
                } else {
                    preparedStatement = connection.prepareStatement(statementString);
                }
            } catch (SQLException ex) {
                throw new DatabaseException(ex);
            } catch (MissingResourceException ex) {
                if (!ex.getMessage().contains("key MERGE_PROPERTY")) {
                    throw new DatabaseException(ex);
                }
            }
            if (preparedStatement != null) {
                preparedStatements.put(key, preparedStatement);
            }
        }
    }
1093688
protected final void doInsert(Connection c) throws SQLException {
		PreparedStatement stmt = null;
		try {
			stmt = c.prepareStatement("insert into foo values (?, ?)  ");
			stmt.setInt(1, rand.nextInt(99999));
			stmt.setString(2, "This is a text");
			stmt.executeUpdate();
		} finally {
			if (stmt != null) {
				stmt.close();
			}
		}
	}
4830
public function prepareSQL($sql, $binds = [])
    {
        $prepare = $this->getConnection()->prepare($sql);

        if (!$prepare) {
            throw new Exception('Cannot prepare statement');
        }

        $this->bindBinds($prepare, $binds);

        $prepare->setFetchMode(\PDO::FETCH_OBJ);

        return $prepare;
    }
894764
@Override
	protected void handleException(final SqlContext sqlContext, final SQLException ex) throws SQLException {
		SQLException cause = ex;

		while (cause.getNextException() != null) {
			cause = cause.getNextException();
		}

		if (LOG.isErrorEnabled() && isOutputExceptionLog()) {
			StringBuilder builder = new StringBuilder();
			builder.append(System.lineSeparator()).append("Exception occurred in SQL execution.")
					.append(System.lineSeparator());
			builder.append("Executed SQL[").append(sqlContext.getExecutableSql()).append("]")
					.append(System.lineSeparator());
			if (sqlContext instanceof SqlContextImpl) {
				Parameter[] bindParameters = ((SqlContextImpl) sqlContext).getBindParameters();
				for (int i = 0; i < bindParameters.length; i++) {
					Parameter parameter = getSqlFilterManager().doParameter(bindParameters[i]);
					builder.append("Bind Parameter.[INDEX[").append(i + 1).append("], ").append(parameter.toString())
							.append("]").append(System.lineSeparator());
				}
			}
			LOG.error(builder.toString(), cause);
		}

		throw cause;
	}
1306935
public List<Object[]> select(Sql sql) throws SQLException {
		
		long start =  System.currentTimeMillis();
		
		if (sql.validate() == false) {
			return null;
		}
		
		List<Object[]> dataList = null;
		
		if (sql.isSelect()) {
			
			ResultSet rs = null;
			PreparedStatement stmt = null;

			try {
				stmt = this.createStatment(conn, sql);
				rs = stmt.executeQuery();
				
				dataList = getResultSet(rs);

			} catch (SQLException e) {
				throw e;
			} finally {
				try {
					if (rs != null && rs.isClosed() == false) {
						rs.close();
					}
					if (stmt != null && stmt.isClosed() == false) {
						stmt.close();
					}
				} catch (SQLException e) {
					throw e;
				}
			}
		}
		
		logger.debug(String.format("Execute %s used %d ms", sql.getSql(), System.currentTimeMillis() - start));
		
		return dataList;
	}
53241
private PreparedStatement buildPreparedStatement(Connection connection, QueryModel queryModel)
            throws SQLException {
        PreparedStatement preparedStatement = connection.prepareStatement(buildSelectString(queryModel));

        int parameterLocation = 1;
        for (Condition condition : queryModel.getConditions()) {
            JDBCConstraint jdbcConstraint = (JDBCConstraint) condition.getConstraint();

            if (jdbcConstraint.getParameter1() != null) {
                preparedStatement.setObject(parameterLocation++, jdbcConstraint.getParameter1());
            }

            if (jdbcConstraint.getParameter2() != null) {
                preparedStatement.setObject(parameterLocation++, jdbcConstraint.getParameter2());
            }
        }

        return preparedStatement;
    }
802290
public DbPreparedStatement<T> bindBean(@NotNull Object bean) throws SQLException {
        return bindBean(dbConnection.db, bean, true);
    }
393974
public PrepareResult executeBatch() throws SQLException {
    int paramCount = getParamCount();
    if (binaryProtocol) {
      if (readPrepareStmtResult) {
        parameterTypeHeader = new ColumnType[paramCount];
        if (prepareResult == null
            && protocol.getOptions().cachePrepStmts
            && protocol.getOptions().useServerPrepStmts) {
          String key = protocol.getDatabase() + "-" + sql;
          prepareResult = protocol.prepareStatementCache().get(key);
          if (prepareResult != null && !((ServerPrepareResult) prepareResult)
              .incrementShareCounter()) {
            //in cache but been de-allocated
            prepareResult = null;
          }
        }
        statementId =
            (prepareResult == null) ? -1 : ((ServerPrepareResult) prepareResult).getStatementId();
      } else if (prepareResult != null) {
        statementId = ((ServerPrepareResult) prepareResult).getStatementId();
      }
    }
    return executeBatchStandard(paramCount);
  }