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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:38:59+00:00 2026-05-28T18:38:59+00:00

Im currently wishing to transfer data from a remote server by capturing printed data

  • 0

Im currently wishing to transfer data from a remote server by capturing printed data via PHP, which is stored into the device’s SQLite database afterwards.

The problem is that sometimes I need to receive over 6.000 rows from a table, it isn’t effective storing all that data in the device’s RAM memory (variables), so I was wondering if someone please could tell me how to save the incoming data into the device’s memory (sd, assets or resources) and delete it after being processed into the SQLite database. The method I’m currently using to receive the data is this:

public JSONArray requestTable(List<NameValuePair> nameValuePairs) throws     ClientProtocolException, IOException, JSONException, UnknownHostException, ConnectTimeoutException
{
  //NameValuePairs contains the Query so it can be catched by php's $_POST

       HttpClient httpclient = new DefaultHttpClient();
   HttpPost httppost = new HttpPost(http://something.php);
   HttpParams httpparams = new BasicHttpParams();

   HttpConnectionParams.setConnectionTimeout(httpparams, msTimeout);
   JSONArray tableData = null;
       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));

   HttpResponse httpresponse = httpclient.execute(httppost);

       Log.i("How are you?", httpresponse.getStatusLine().toString());

       HttpEntity entity = httpresponse.getEntity();


    if (entity != null)
    {
        InputStream instream = entity.getContent();
        String result= convertStreamToString(instream);
            if(result.charAt(0) == '<')
                Log.e("php error", result);
            else
                tableData = new JSONArray(result);

        instream.close();
        httpresponse = null;
        return tableData;
    }

    else
        return null;



private static String convertStreamToString(InputStream is) {

    BufferedReader reader = new BufferedReader(new InputStreamReader(is), 16 * 1024);
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) 
        {
            sb.append(line);
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    finally 
    {
        try 
        {
            is.close();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }
    }

    return sb.toString();
}

By using this method I get this error:

01-22 17:43:54.098: INFO/dalvikvm-heap(380): Grow heap (frag case) to 18.874MB for 2834992-byte allocation
01-22 17:44:06.368: INFO/dalvikvm-heap(380): Forcing collection of SoftReferences for 4252484-byte allocation

01-22 17:44:08.490: ERROR/dalvikvm-heap(380): Out of memory on a 4252484-byte allocation.
01-22 17:44:08.490: INFO/dalvikvm(380): "Thread-8" prio=5 tid=7 RUNNABLE
01-22 17:44:08.490: INFO/dalvikvm(380):   | group="main" sCount=0 dsCount=0 s=N obj=0x44f182d8 self=0x118bf8
01-22 17:44:08.490: INFO/dalvikvm(380):   | sysTid=389 nice=0 sched=0/0 cgrp=default handle=2525744
01-22 17:44:08.498: INFO/dalvikvm(380):   | schedstat=( 328938307540 280414788056 42400 )
01-22 17:44:08.498: INFO/dalvikvm(380):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~97)
01-22 17:44:08.498: INFO/dalvikvm(380):   at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:136)
01-22 17:44:08.498: INFO/dalvikvm(380):   at  java.lang.StringBuilder.append(StringBuilder.java:272)
01-22 17:44:08.498: INFO/dalvikvm(380):   at java.io.BufferedReader.readLine(BufferedReader.java:452)
01-22 17:44:08.498: INFO/dalvikvm(380):   at srdroid.cata.Server.convertStreamToString(Server.java:628)  
01-22 17:44:08.498: INFO/dalvikvm(380):   at srdroid.cata.Server.requestTable(Server.java:226)
01-22 17:44:08.498: INFO/dalvikvm(380):   at      srdroid.cata.Server$2.run(Server.java:418)
01-22 17:44:08.498: INFO/dalvikvm(380):   at java.lang.Thread.run(Thread.java:1096)

Sorry for the long post, any help will be greatly appreciated!

  • 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-28T18:39:00+00:00Added an answer on May 28, 2026 at 6:39 pm

    Look at Google’s GSON Library, in particular the JsonReader class.

    You can use this to “pull” JSON data out element by element rather than reading the entire document into an object structure (which as you say has a large memory impact). You can then read one row of JSON data at a time and write it to the DB.

    JsonReader is actually part of Android from API level 11. If you’re compiling against an earlier version of Android you can use the GSON stream jar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Currently I'm doing some unit tests which are executed from bash. Unit tests are
Currently I know of only two ways to cache data (I use PHP but
After some advice. I have a client wishing to have an app which lets
Sometimes procedural programming is absolutely unavoidable when processing data. I am currently working on
Currently I am loooking for a way to develop an algorithm which is supposed
Currently my server is running of the Tomcat 5.5.26 and JDK 1.5.15. Now I
Currently, I am copying a database from my assets folder to the to the
Currently, working with RC0 Denali, having some issues I am attempting to review data
I am currently in the process of finishing a website which required tables to

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.