Java SQL PreparedStatement setValues(PreparedStatement preparedStatement, Object... values)

Here you can find the source of setValues(PreparedStatement preparedStatement, Object... values)

Description

See comments on #preparePlaceHolders(int)

License

Open Source License

Declaration

public static void setValues(PreparedStatement preparedStatement, Object... values) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.util.Collection;

public class Main {
    /** /*from  ww w . j  a v  a  2s.c o  m*/
     * See comments on {@link #preparePlaceHolders(int)}
     */
    public static void setValues(PreparedStatement preparedStatement, Object... values) throws SQLException {

        for (int i = 0; i < values.length; i++) {
            preparedStatement.setObject(i + 1, values[i]);
        }
    }

    /** 
     * See comments on {@link #preparePlaceHolders(int)}
     */
    public static void setValues(PreparedStatement preparedStatement, Collection<?> values) throws SQLException {

        int i = 0;
        for (Object o : values) {
            preparedStatement.setObject(++i, o);
        }
    }
}

Related

  1. setByte(PreparedStatement statement, int index, Byte value)
  2. setBytes(PreparedStatement pstmt, int index, byte[] bytes)
  3. setValue(PreparedStatement ps, int paramIndex, Object inValue)
  4. setValue(PreparedStatement ps, int posicion, int tipo, String strDefault, String strValor)
  5. setValueIndex(PreparedStatement stmt, int index, int valueIndex)
  6. setValues(PreparedStatement statement, Object... values)
  7. setValues(PreparedStatement statement, Object... values)
  8. setValues(PreparedStatement statement, Object[] values)
  9. substitute(PreparedStatement stmt, Object[] params)