Here you can find the source of importCsvDataInTable(int offsetIndex, Connection connection, PreparedStatement preparedStatement, String[] columnMapping, List> data, Map
private static void importCsvDataInTable(int offsetIndex, Connection connection, PreparedStatement preparedStatement, String[] columnMapping, List<List<String>> data, Map<Integer, List<String>> notInsertedData) throws Exception
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.PreparedStatement; import java.util.List; import java.util.Map; public class Main { private static void importCsvDataInTable(int offsetIndex, Connection connection, PreparedStatement preparedStatement, String[] columnMapping, List<List<String>> data, Map<Integer, List<String>> notInsertedData) throws Exception { int csvLineIndex = offsetIndex; for (List<String> csvLine : data) { csvLineIndex++;//from w w w . jav a 2s . com if (csvLine.size() != columnMapping.length) { notInsertedData.put(csvLineIndex, csvLine); } else { int parameterIndex = 1; for (int csvValueIndex = 0; csvValueIndex < csvLine.size(); csvValueIndex++) { if (columnMapping[csvValueIndex] != null) { preparedStatement.setString(parameterIndex++, csvLine.get(csvValueIndex)); } } try { preparedStatement.execute(); connection.commit(); } catch (Exception e) { notInsertedData.put(csvLineIndex, csvLine); connection.rollback(); } } } } }