Java SQL PreparedStatement writeList(Connection connection, PreparedStatement preparedStatement, int column, Class type, List list)

Here you can find the source of writeList(Connection connection, PreparedStatement preparedStatement, int column, Class type, List list)

Description

write List

License

Open Source License

Declaration

public static <T> void writeList(Connection connection, PreparedStatement preparedStatement, int column,
            Class<T> type, List<T> list) throws SQLException 

Method Source Code

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

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.util.List;

public class Main {
    public static <T> void writeList(Connection connection, PreparedStatement preparedStatement, int column,
            Class<T> type, List<T> list) throws SQLException {
        @SuppressWarnings("unchecked")
        T[] array = (T[]) list.toArray();
        writeArray(connection, preparedStatement, column, type, array);
    }/*from  w w  w .j av  a2  s  . co m*/

    public static <T> void writeArray(Connection connection, PreparedStatement preparedStatement, int column,
            Class<T> type, T[] array) throws SQLException {
        if (type == String.class) {
            java.sql.Array sqlArray = connection.createArrayOf("VARCHAR", array);
            preparedStatement.setArray(column, sqlArray);
        } else {
            throw new IllegalArgumentException("Type '" + type.getName() + "' is not supported.");
        }
    }
}

Related

  1. setValues(PreparedStatement statement, Object... values)
  2. setValues(PreparedStatement statement, Object... values)
  3. setValues(PreparedStatement statement, Object[] values)
  4. substitute(PreparedStatement stmt, Object[] params)
  5. writeArray(Connection connection, PreparedStatement preparedStatement, int column, Class type, T[] array)
  6. writeMap(Connection connection, PreparedStatement preparedStatement, int keyColumn, int valueColumn, Class keyType, Class valueType, Map map)
  7. writeProperties(Connection connection, PreparedStatement preparedStatement, int keyColumn, int valueColumn, Properties properties)