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 6769533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:12:17+00:00 2026-05-26T15:12:17+00:00

I have to fetch 500K rows from the database and write that data into

  • 0

I have to fetch 500K rows from the database and write that data into the file , Means perform the I/O operation . I have done for two steps .

  1. Write each row one by one into the file .
  2. Make the chunk of those rows .Append those rows in StringBuffer and then print it . This one will be better but is there any way that File I/O can make the buffer on it’s own without using StringBuffer . As this String Buffer is taking more time (Internally it use Arrays.copyOf)

Please suggest me on this
Please find the code attached with this

public void fetchDataWithChunkSpace(Connection con)throws Exception
        {
            String query ="select * from lis.testxml  ";
            long startTime=new Date().getMinutes();
            PreparedStatement stmt = con.prepareStatement(query);
            ResultSet rs = stmt.executeQuery();
            PrintWriter pw = new PrintWriter(new File("c:\\test_chunkSpace.xml"));
            pw.write("<?xml version='1.0' encoding='UTF-8'?>");
            StringBuffer sb = new StringBuffer();
            String t=null; 
            long count =0;
            while(rs.next())
            {   count++;
                t = rs.getString("xmltest");
                sb = sb.append(t);
                if(count%100==0)
                {
                 pw.write(sb.toString());
                 sb = new StringBuffer();
                 System.out.println(count);
                }
            }
            pw.write("\n");
            pw.write("</EndTag>");
            pw.close();
            stmt.close();
            con.close();
            long endTime=new Date().getMinutes();
            System.out.println("chunkSpace  ---> " + (endTime-startTime));
        }
  • 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-26T15:12:18+00:00Added an answer on May 26, 2026 at 3:12 pm

    Look at BufferedOutputStream or BufferedWriter.

    Also consider that StringBuffer is thread-safe class with synchronyzed methods unlike StringBuilder.

    Update.
    Try this code:

    Writer pw = new BufferedWriter(new PrintWriter(new File("c:\\test_chunkSpace.xml")));
    pw.write("<?xml version='1.0' encoding='UTF-8'?>");
    String t;
    while (rs.next()) {
        t = rs.getString("xmltest");
        pw.write(t);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to display data from the database in a listview. I have fetch
I have to display data from the database in a listview. I have fetch
I have the following Query and i need the query to fetch data from
I have to fetch only 50 records at a time from database (DB2), for
I have the following table, from which i have to fetch non unique rows
We have a data warehouse with denormalized tables ranging from 500K to 6+ million
I have a requirement where I have to fetch some records from the database
I have a fetch function that injects rss content into a page for me.
I'm working an application that periodically fetch data from a web service. The problem
I have to fetch all the files from a folder and i am using

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.