Bind object to {@link PreparedStatement}. Can be overridden by subclasses to
implement custom argument binding.

@param ps    statement to bind object to
@param index index of the parameter
@param value to bind
@throws SQLException if something fails
11028
public void bindArgument(@NotNull PreparedStatement ps, int index, @Nullable Object value) throws SQLException {
        ArgumentBinder.bindArgument(ps, index, value);
    }
1289008
public void bindInsert(PreparedStatement stmt, ClassDescriptor cld, Object obj) throws java.sql.SQLException
    {
        ValueContainer[] values;
        cld.updateLockingValues(obj); // BRJ : provide useful defaults for locking fields

        if (cld.getInsertProcedure() != null)
        {
            this.bindProcedure(stmt, cld, obj, cld.getInsertProcedure());
        }
        else
        {
            values = getAllValues(cld, obj);
            for (int i = 0; i < values.length; i++)
            {
                setObjectForStatement(stmt, i + 1, values[i].getValue(), values[i].getJdbcType().getType());
            }
        }
    }
823479
public void bindSelect(PreparedStatement stmt, Identity oid, ClassDescriptor cld, boolean callableStmt) throws SQLException
    {
        ValueContainer[] values = null;
        int i = 0;
        int j = 0;

        if (cld == null)
        {
            cld = m_broker.getClassDescriptor(oid.getObjectsRealClass());
        }
        try
        {
            if(callableStmt)
            {
                // First argument is the result set
                m_platform.registerOutResultSet((CallableStatement) stmt, 1);
                j++;
            }

            values = getKeyValues(m_broker, cld, oid);
            for (/*void*/; i < values.length; i++, j++)
            {
                setObjectForStatement(stmt, j + 1, values[i].getValue(), values[i].getJdbcType().getType());
            }
        }
        catch (SQLException e)
        {
            m_log.error("bindSelect failed for: " + oid.toString() + ", PK: " + i + ", value: " + values[i]);
            throw e;
        }
    }
633268
public static PreparedStatement setInts(int index, PreparedStatement stmt, int... params)
			throws SQLException {
		return set(index, stmt, params, null, null);
	}
802290
public DbPreparedStatement<T> bindBean(@NotNull Object bean) throws SQLException {
        return bindBean(dbConnection.db, bean, true);
    }
162023
private PreparedStatement prepareBatchStatement(String sql)
    {
        String sqlCmd = sql.substring(0, 7);

        if (sqlCmd.equals("UPDATE ") || sqlCmd.equals("DELETE ") || (_useBatchInserts && sqlCmd.equals("INSERT ")))
        {
            PreparedStatement stmt = (PreparedStatement) _statements.get(sql);
            if (stmt == null)
            {
                // [olegnitz] for JDK 1.2 we need to list both PreparedStatement and Statement
                // interfaces, otherwise proxy.jar works incorrectly
                stmt = (PreparedStatement) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{
                        PreparedStatement.class, Statement.class, BatchPreparedStatement.class},
                        new PreparedStatementInvocationHandler(this, sql, m_jcd));
                _statements.put(sql, stmt);
            }
            return stmt;
        }
        else
        {
            return null;
        }
    }
813652
private int bindStatement(PreparedStatement stmt, int index, InCriteria crit, ClassDescriptor cld) throws SQLException
    {
        if (crit.getValue() instanceof Collection)
        {
            Collection values = (Collection) crit.getValue();
            Iterator iter = values.iterator();

            while (iter.hasNext())
            {
                index = bindStatementValue(stmt, index, crit.getAttribute(), iter.next(), cld);
            }
        }
        else
        {
            index = bindStatementValue(stmt, index, crit.getAttribute(), crit.getValue(), cld);
        }
        return index;
    }
1209756
static void setParameters(PreparedStatement ps, List<Parameter> params, boolean namesAllowed)
            throws SQLException {
        for (int i = 1; i <= params.size(); i++) {
            if (params.get(i - 1).hasName() && !namesAllowed)
                throw new SQLException("named parameter found but sql does not contain names");
            Object o = params.get(i - 1).value();
            try {
                if (o == null)
                    ps.setObject(i, null);
                else if (o == Database.NULL_CLOB)
                    ps.setNull(i, Types.CLOB);
                else if (o == Database.NULL_BLOB)
                    ps.setNull(i, Types.BLOB);
                else {
                    Class<?> cls = o.getClass();
                    if (Clob.class.isAssignableFrom(cls)) {
                        setClob(ps, i, o, cls);
                    } else if (Blob.class.isAssignableFrom(cls)) {
                        setBlob(ps, i, o, cls);
                    } else if (Calendar.class.isAssignableFrom(cls)) {
                        Calendar cal = (Calendar) o;
                        Timestamp t = new java.sql.Timestamp(cal.getTimeInMillis());
                        ps.setTimestamp(i, t, cal);
                    } else if (Time.class.isAssignableFrom(cls)) {
                        Calendar cal = Calendar.getInstance();
                        ps.setTime(i, (Time) o, cal);
                    } else if (Timestamp.class.isAssignableFrom(cls)) {
                        Calendar cal = Calendar.getInstance();
                        ps.setTimestamp(i, (Timestamp) o, cal);
                    } else if (java.sql.Date.class.isAssignableFrom(cls)) {
                        Calendar cal = Calendar.getInstance();
                        ps.setDate(i, (java.sql.Date) o, cal);
                    } else if (java.util.Date.class.isAssignableFrom(cls)) {
                        Calendar cal = Calendar.getInstance();
                        java.util.Date date = (java.util.Date) o;
                        ps.setTimestamp(i, new java.sql.Timestamp(date.getTime()), cal);
                    } else
                        ps.setObject(i, o);
                }
            } catch (SQLException e) {
                log.debug("{} when setting ps.setObject({},{})", e.getMessage(), i, o);
                throw e;
            }
        }
    }
234856
public static void setArguments(PreparedStatement statement,
			Object[] selectionArgs) throws SQLException {
		if (selectionArgs != null) {
			for (int i = 0; i < selectionArgs.length; i++) {
				statement.setObject(i + 1, selectionArgs[i]);
			}
		}
	}
886618
public void createPreparedStatement(String query, List<Object> params) throws SQLException {

        m_preparedStatement = m_connection.prepareStatement(query);

        // Check the params
        if (params != null) {
            for (int i = 0; i < params.size(); i++) {
                Object item = params.get(i);

                // Check if the parameter is a string
                if (item instanceof String) {
                    m_preparedStatement.setString(i + 1, (String)item);
                }
                if (item instanceof Integer) {
                    Integer number = (Integer)item;
                    m_preparedStatement.setInt(i + 1, number.intValue());
                }
                if (item instanceof Long) {
                    Long longNumber = (Long)item;
                    m_preparedStatement.setLong(i + 1, longNumber.longValue());
                }

                // If item is none of types above set the statement to use the bytes
                if (!(item instanceof Integer) && !(item instanceof String) && !(item instanceof Long)) {
                    try {
                        m_preparedStatement.setBytes(i + 1, CmsDataTypeUtil.dataSerialize(item));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    }
1199777
public void setValues(PreparedStatement pstmt) throws SQLException {
		int i = 1;
		for (Class<?> type : this.type) {
			this.setValues(pstmt, i, type);
			i++;
		}
	}
714144
protected int setStreamParameter(final PreparedStatement preparedStatement, int index,
			final BindParameterMapperManager parameterMapperManager) throws SQLException {

		if (len > -1) {
			preparedStatement.setBinaryStream(index, stream, len);
		} else {
			preparedStatement.setBinaryStream(index, stream);
		}

		parameterLog(index);
		index++;

		return index;
	}
671435
public static BoundStatement bind(PreparedStatement statement, Object[] params) {
        if(CQL_LOGGER.isDebugEnabled()) {
            CQL_LOGGER.debug("{} parameters ({})", statement.getQueryString(), StringUtils.join(params, ","));
        }
        return statement.bind(params);
    }
952974
public void setObject(final int parameterIndex, 
                          final Object x) throws SQLException {

        if (x == null) {
            if ("true".equals(connection.getProperties().
                              get("acolyte.parameter.untypedNull"))) {

                // Fallback to String-VARCHAR
                setObject(parameterIndex, null, Types.VARCHAR);

                return;
            } // end of if

            throw new SQLException("Cannot set parameter from null object");
        } // end of if

        // ---

        final String className = normalizeClassName(x.getClass());

        if (!Defaults.jdbcTypeClasses.containsKey(className)) {
            throw new SQLFeatureNotSupportedException("Unsupported parameter type: " + className);
        } // end of if
        
        // ---

        final int sqlType = Defaults.jdbcTypeClasses.get(className);

        setObject(parameterIndex, x, sqlType);
    }
39325
public void execute(String query, Object... params) throws SQLException {
        createPreparedStatement(query, 0, params).execute();
    }
320369
private static void setBlob(PreparedStatement ps, int i, Object o, Class<?> cls)
            throws SQLException {
        final InputStream is;
        if (o instanceof byte[]) {
            is = new ByteArrayInputStream((byte[]) o);
        }
1328455
private int bindStatement(PreparedStatement stmt, int index, BetweenCriteria crit, ClassDescriptor cld) throws SQLException
    {
        index = bindStatementValue(stmt, index, crit.getAttribute(), crit.getValue(), cld);

        return bindStatementValue(stmt, index, crit.getAttribute(), crit.getValue2(), cld);
    }