title: Insert array data into database using Java
body: <p>I have problem with this code..I want to extract data from flat file and store it into database. flat file format is like this:-</p>
  
  <pre><code>DT|00000001|TMDWH|UNIFI|00380520160|MAH SIEW YIN|11  |JALAN PP 2/8|TAMAN PUTRA PRIMA|PUCHONG|SELANGOR|47100|MALAYSIA|801110-14-5498||||||VOBB||A||11|JALAN PP 2/8|||TAMAN PUTRA PRIMA
  
  DT|00000002|TMDWH|UNIFI|00322012091|JUNITA BINTI JAMAL|6 10 KONDOMINIUM FAJARIA|JALAN PANTAI BARU|KUALA LUMPUR|KUALA LUMPUR|WILAYAH PERSEKUTUAN|59200|MALAYSIA|800129-09-5078||||||VOBB||A|||JALAN PANTAI BARU|6|KONDOMINIUM FAJARIA|KUALA LUMPUR                                                                                     
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>public void massageData(String tmp) {
  
          String RecordType = "";
          String RecordNumber = "";
          String sourceSystemId = "";
          String targetSystemId = "";
          String TelNo = "";
          String Name = "";
          String Addr1 = "";
          String Addr2 = "";
          String Addr3 = "";
          String TownCity = "";
          String State = "";
          String PostalCd = "";
          String Country = "";
          String NewICNo = "";
          String OldICNo = "";
          String PassportNo = "";
          String BRN = "";
          String Latitude = "";
          String Longitude = "";
          String ServiceType = "";
          String IndicatorType = "";
          //add
          String CreateDate = "";
          String Filler = "";
          String CRNL = "";
  
          String HouseNo = "";
          String LotNo = "";
          String StreetName = "";
          String AptNo = "";
          String BuildingName = "";
          //add
          String LowID = "";
          String HighID = "";
  
          String SectionName = "";
  
          tmp = tmp.replace("\""," ");            // remove " with blank
          tmp = tmp.replace("\'","\'\'"); 
          String[] recArray = tmp.split("\\|");
  
          RecordType = recArray[1].trim();    
          RecordNumber = recArray[2].trim();
          sourceSystemId = recArray[3].trim();
          targetSystemId = recArray[4].trim();
          TelNo = recArray[5].trim();
          Name = recArray[6].trim();
          Addr1 = recArray[7].trim();
          Addr2 = recArray[8].trim();
          Addr3 = recArray[9].trim();
          TownCity = recArray[10].trim();
          State = recArray[11].trim();
          PostalCd = recArray[12].trim();
          Country = recArray[13].trim();
          NewICNo = recArray[14].trim();
          OldICNo = recArray[15].trim();
          PassportNo = recArray[16].trim();
          BRN = recArray[17].trim();
          Latitude = recArray[18].trim();
          Longitude = recArray[19].trim();
          ServiceType = recArray[20].trim();
          IndicatorType = recArray[21].trim();
          //add
          CreateDate = recArray[22].trim();
          Filler = recArray[23].trim();
          CRNL = recArray[24].trim();
          //
  
          HouseNo = recArray[25].trim();
          LotNo = recArray[26].trim();
          StreetName = recArray[27].trim();
          AptNo = recArray[28].trim();
          BuildingName = recArray[29].trim();
          //add
          LowID = recArray[30].trim();
          HighID = recArray[31].trim();
          //
          SectionName = recArray[32].trim();
  
          Connection conn = null;
          ResultSet rs = null;
          PreparedStatement stmt = null;
          logger.info("masuk messageData");
          // get actual telephone number
          String actualMSISDN = parseMSISDN(TelNo);
  
              String [] aNo = getAreaCode(actualMSISDN).split("\\|");
              String iCtr = getiCtr(actualMSISDN);
              iCtr = recArray[0].trim();
              String stateCode = lookupStateCode(State);
              String  sQuery = "insert into DATA_999 (ID,RecordType,RecordNumber,SourceSystemApplicationId,TargetApplicationId,TelNo,Name,HouseNo,StreetName,AppartmentSuite,TownCity,State,PostalCode,Country,NewIC,OldIC,PassportNo,BRN,LatitudeDecimal,LongitudeDecimal,ServiceType,IndicatorType,CreateDate,Filler,Cr_Nl,HouseNo_New,LotNo_New,StreetName_New,AptNo_New,BuildingName_New,LowIDRange,HighIDRange,SectionName) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
              try {   
                  conn = ds.getConnection();
                  // insert post process data to data_999 table
                  logger.info("start Query");
  
                  stmt = conn.prepareStatement(sQuery);
                  stmt.setString(0,iCtr);
                  stmt.setString(1,RecordType);
                  stmt.setString(2,RecordNumber);
                  stmt.setString(3,sourceSystemId);
                  stmt.setString(4,targetSystemId);
                  stmt.setString(5,TelNo);
                  stmt.setString(6,Name);
                  stmt.setString(7,Addr1);
                  stmt.setString(8,Addr2);
                  stmt.setString(9,Addr3);
                  stmt.setString(10,TownCity);
                  stmt.setString(11,State);
                  stmt.setString(12,PostalCd);
                  stmt.setString(13,Country);
                  stmt.setString(14,NewICNo);
                  stmt.setString(15,OldICNo);
                  stmt.setString(16,PassportNo);
                  stmt.setString(17,BRN);
                  stmt.setString(18,Latitude);
                  stmt.setString(19,Longitude);
                  stmt.setString(20,ServiceType);
                  stmt.setString(21,IndicatorType);
                  //add
                  stmt.setString(22,CreateDate);
                  stmt.setString(23,Filler);
                  stmt.setString(24,CRNL);
                  //
                  stmt.setString(25,HouseNo);
                  stmt.setString(26,LotNo);
                  stmt.setString(27,StreetName);
                  stmt.setString(28,AptNo);
                  stmt.setString(29,BuildingName);
                  //add
                  stmt.setString(30,LowID);
                  stmt.setString(31,HighID);
                  //
                  stmt.setString(32,SectionName);
  
                  //stmt = conn.prepareStatement(sQuery);
                  int dbStat = stmt.executeUpdate();
                  conn.close();
              } catch (SQLException s){
                  logger.error(s.getMessage());
              }
              finally {
                  try {if (stmt != null) stmt.close();} catch (SQLException e) {}
                  try {if (conn != null) conn.close();} catch (SQLException e) {}
              }
  </code></pre>
  
  <p>I really2 hope anyone here can help me. </p>
  
  <p>Current result:</p>
  
  <blockquote>
    <p>No data store into database, the code was successfully compiled!</p>
  </blockquote>
  
  <p>Expected result</p>
  
  <blockquote>
    <p>All the data will store into database DATA_999.</p>
  </blockquote>