Java SQL PreparedStatement importCsvDataInTable(int offsetIndex, Connection connection, PreparedStatement preparedStatement, String[] columnMapping, List> data, Map> notInsertedData)

Here you can find the source of importCsvDataInTable(int offsetIndex, Connection connection, PreparedStatement preparedStatement, String[] columnMapping, List> data, Map> notInsertedData)

Description

import Csv Data In Table

License

Open Source License

Declaration

private static void importCsvDataInTable(int offsetIndex, Connection connection,
            PreparedStatement preparedStatement, String[] columnMapping, List<List<String>> data,
            Map<Integer, List<String>> notInsertedData) throws Exception 

Method Source Code

//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();
                }
            }
        }
    }
}

Related

  1. getPreparedStatement(Connection conn, String sql)
  2. getPreparedStatement(Connection conn, String sql, List sqlParams, boolean getGeneratedKeys)
  3. getPreparedStatement(String sql)
  4. getPriorID(Connection conn, PreparedStatement stmt)
  5. getScalarValue(PreparedStatement ps)
  6. intToArray(final int[] arr)
  7. isClosed(PreparedStatement ps, boolean defaultValue)
  8. loadColumnTableNameList(PreparedStatement stmt)
  9. LockRow(PreparedStatement pstmt, String tablename, boolean exclusiveMode)

  10. HOME | Copyright © www.java2s.com 2016