0

私はプログラムを書きました。列 1 を "Slno" に、列 2 を "COM_BUS" にマップする方法。例:
CSV ファイルのヘッダーに「sln」「C_BUS」がある

テーブル「ビジネス」には、列に「SLNO」「COMBUS」があります。

私の質問は、データを db2 テーブルにインポートする際に、csv ファイルのヘッダーが問題になるべきではないということです。助けてください。

プライベート スタティック ファイナル

String SQL_INSERT = "INSERT INTO OPTYMGT.${table}(${keys}, RUN_TS)   
                       VALUES(${values}, current_timestamp)";

private static final String TABLE_REGEX = "\\$\\{table\\}";
private static final String KEYS_REGEX = "\\$\\{keys\\}";
private static final String VALUES_REGEX = "\\$\\{values\\}";

private char seprator= ',';




public boolean loadCSV(Connection connection,String csvFile, String tableName) throws Exception {
    boolean  result = true;
    CSVReader csvReader = null;
    if(connection == null) {
        throw new Exception("Not a valid connection.");
    }
    try {

        csvReader = new CSVReader(new FileReader(csvFile), this.seprator);
        //System.out.println("csvReader" +csvReader);

    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("Error occured while executing file. "
                + e.getMessage());
    }

    String[] headerRow = csvReader.readNext();

    //System.out.println("headerRow" +headerRow);

    if (null == headerRow) {
        throw new FileNotFoundException(
                "No columns defined in given CSV file." +
                "Please check the CSV file format.");
    }

    String questionmarks = StringUtils.repeat("?,", headerRow.length);
    questionmarks = (String) questionmarks.subSequence(0, questionmarks.length() - 1);
    String query = SQL_INSERT.replaceFirst(TABLE_REGEX, tableName);
    query = query.replaceFirst(KEYS_REGEX, StringUtils.join(headerRow, ","));
    query = query.replaceFirst(VALUES_REGEX, questionmarks);

    //System.out.println("Query: " + query);

/*  SimpleDateFormat cDate = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
    Date now = new Date();
    String ccDate = cDate.format(now);
    System.out.println("ccdate" +ccDate);*/

    String[] nextLine;
    Connection con = null;
    PreparedStatement ps = null;
4

1 に答える 1