0 Replies Latest reply on Aug 6, 2019 2:04 PM by user12251389

    import date and ignore other strings in java

    user12251389

      I am fetching data from file using filestream and importing this data into oracle tables. I have column 'FT__FIRST' which is Date data type in oracle table and where i only need date values to be inserted and ignore other values.

      From file the date is coming in format 'YYYYMMDD'. In future if there is other values coming from file rather than Date datatype for this column and if it tries to insert into oracle table then the java code might throw an error as literal string does not match.

      So to avoid this issue i want to modify my java code such that it can take only insert date format value and ignore other values.

      Currently i am handling only specific string from file which i know and ignoring it as they are not date format..

       

      private String createUpdateTableSql(String line, String tableName, String dateFormat, List<ColumnData> columnData) {
         List<String> data = Splitter.on("|").trimResults().splitToList(line);
         String ftFirst = "";
         String tr = "";
         String pds = "";
      
         for (int i = 0; i < columnData.size(); i++) {
         if(columnData.get(i) == null || "N.A.".equalsIgnoreCase(data.get(i)) || "N.A".equalsIgnoreCase(data.get(i)) || "UNKNOWN".equalsIgnoreCase(data.get(i))) {
         continue;
         }
      
         if ("FT_FIRST".equalsIgnoreCase(columnData.get(i).getName().trim())) {
        ftFirst = data.get(i);
         }
      
         if ("TR".equalsIgnoreCase(columnData.get(i).getName().trim())) {
        tr = data.get(i);
         }
      
         if ("P_S_SOURCE".equalsIgnoreCase(columnData.get(i).getName().trim())) {
        pds = data.get(i);
         }   
      
         }
      
         return "UPDATE " + tableName + " " + 
         "SET FT_FIRST=to_date('" + ftFirst + "','YYYYMMDD')" +
         " WHERE TR='" + ticker + 
         "' AND P_S_SOURCE='" + pds + "'";   
         }