Here you can find the source of writeMap(Connection connection, PreparedStatement preparedStatement, int keyColumn, int valueColumn, Class
public static <K, V> void writeMap(Connection connection, PreparedStatement preparedStatement, int keyColumn, int valueColumn, Class<K> keyType, Class<V> valueType, Map<K, V> map) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { public static <K, V> void writeMap(Connection connection, PreparedStatement preparedStatement, int keyColumn, int valueColumn, Class<K> keyType, Class<V> valueType, Map<K, V> map) throws SQLException { List<K> keys = new ArrayList<>(map.keySet()); List<V> values = new ArrayList<>(); for (K key : keys) { values.add(map.get(key));/*from w w w . ja v a2 s . c om*/ } @SuppressWarnings("unchecked") K[] keyArray = (K[]) keys.toArray(); @SuppressWarnings("unchecked") V[] valueArray = (V[]) values.toArray(); writeArray(connection, preparedStatement, keyColumn, keyType, keyArray); writeArray(connection, preparedStatement, valueColumn, valueType, valueArray); } 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."); } } }