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

  • Home
  • SEARCH
  • 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 6382133
In Process

The Archive Base Latest Questions

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

Before spending hours trying to figure this out, maybe I can use someone’s expertise;

  • 0

Before spending hours trying to figure this out, maybe I can use someone’s expertise; would it be possible to generate an SQLite database on a (web)server and download it to an Android device and then use it?

I need to sync data, but it probably would be much faster to create the database completely and send that as binary.

  • 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-25T02:29:00+00:00Added an answer on May 25, 2026 at 2:29 am

    Here’s my implementation:

         private static boolean downloadDatabase(Context context) {
                    try {
                           // Log.d(TAG, "downloading database");
                            URL url = new URL("http://some-url.com/db/" + "db_name.s3db");
                            /* Open a connection to that URL. */
                            URLConnection ucon = url.openConnection();
                            /*
                             * Define InputStreams to read from the URLConnection.
                             */
                            InputStream is = ucon.getInputStream();
                            BufferedInputStream bis = new BufferedInputStream(is);
                            /*
                             * Read bytes to the Buffer until there is nothing more to read(-1).
                             */
                            ByteArrayBuffer baf = new ByteArrayBuffer(50);
                            int current = 0;
                            while ((current = bis.read()) != -1) {
                                    baf.append((byte) current);
                            }
    
                            /* Convert the Bytes read to a String. */
                            FileOutputStream fos = null;
                            // Select storage location
                            fos = context.openFileOutput("db_name.s3db", Context.MODE_PRIVATE); 
    
                            fos.write(baf.toByteArray());
                            fos.close();
                           // Log.d(TAG, "downloaded");
                    } catch (IOException e) {
                            Log.e(TAG, "downloadDatabase Error: " , e);
                            return false;
                    }  catch (NullPointerException e) {
                            Log.e(TAG, "downloadDatabase Error: " , e);
                            return false;
                    } catch (Exception e){
                            Log.e(TAG, "downloadDatabase Error: " , e);
                            return false;
                    }
                    return true;
            }
    

    This downloads the database into your applications private storage see here

    Don’t forget you need the internet permission in your manifest.

    To then get an actual database from this file you can do this:

       /**
         * Copies your database from your local downloaded database that is copied from the server 
         * into the just created empty database in the
         * system folder, from where it can be accessed and handled.
         * This is done by transfering bytestream.
         * */
            private void copyServerDatabase() {
                // by calling this line an empty database will be created into the default system path
                // of this app - we will then overwrite this with the database from the server
                SQLiteDatabase db = getReadableDatabase();
                db.close();
    
    
                    OutputStream os = null;
                    InputStream is = null;
                    try {
                          // Log.d(TAG, "Copying DB from server version into app");
                            is = mContext.openFileInput("db_name.s3db");
                            os = new FileOutputStream("/data/data/your.package.name/databases/"); // XXX change this
    
                            copyFile(os, is);
                    } catch (Exception e) {
                            Log.e(TAG, "Server Database was not found - did it download correctly?", e);                          
                    } finally {
                            try {
                                    //Close the streams
                                    if(os != null){
                                            os.close();
                                    }
                                    if(is != null){
                                            is.close();
                                    }
                            } catch (IOException e) {
                                    Log.e(TAG, "failed to close databases");
                            }
                    }
                      // Log.d(TAG, "Done Copying DB from server");
            }
    
    
    
    
         private void copyFile(OutputStream os, InputStream is) throws IOException {
                byte[] buffer = new byte[1024];
                int length;
                while((length = is.read(buffer))>0){
                        os.write(buffer, 0, length);
                }
                os.flush();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

before I start I want to point out that I tagged this question as
After spending 14 hours on this I think its time to share my woes
After spending about 6-8 hours trying to digest the Manacher's algorithm, I am ready
I'm pretty sure this has been asked before but I can't seem to find
Before spending any time reading this, see the self-answer below. The problem was invalid
I would appreciate some help before spending any more time on trial and error.
After spending a couple of hours trying to understand how to make continuous deployment
Is it possible to, before sending a http message, remove some specific http headers
Does someone know a wrapper which would allow SQLite to load its data from
After spending some hours with the Ruby Debugger I finally learned that I need

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.