Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7194299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:20:35+00:00 2026-05-28T20:20:35+00:00

I have problem with this code..I want to extract data from flat file and

  • 0

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:-

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:

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) {}
            }

I really2 hope anyone here can help me.

Current result:

No data store into database, the code was successfully compiled!

Expected result

All the data will store into database DATA_999.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:20:37+00:00Added an answer on May 28, 2026 at 8:20 pm

    The SQL API, unlike every other java API I can think of which is zero-based, is one-based – meaning it starts counting from one. Your code is trying to set the zeroth field, which should be exploding.

    As a side note, because there’s hardy any special processing for each field, you could replace all that code with just a few lines by simply iterating over the fields and setting the stmt params – ie don’t use variables for each field:

    // fyi, the regex of this split trims automatically
    String[] fields = tmp.replace("\""," ").replace("\'","\'\'").trim().split("\\s*\\|\\s*");
    // Do any special field processing (most need none)
    field[0] = getiCtr(parseMSISDN(field[5])); // for example - just do what you need
    // Now set all the SQL params
    int col = 0;
    for (String field : fields) {
        stmt.setString(++col, field); // Note: SQL API is 1-based (not zero-based)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
Hi i have problem with this code, i found it on the internet and
i am a beginner and i have a problem : this code doesnt compile
I'm a beginner with jdbc ... I have a problem running this code :
I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
I have this code, but I have a problem. When I update but do
Never thought I'd have this problem :) The following snippet of code works in
Problem Hello all! I have this code which takes my jpg image loops through
This is an erlang problem, it seems. I have this code to test the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.