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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:17:19+00:00 2026-06-06T23:17:19+00:00

My app needs to download a database from a link, heres the code I

  • 0

My app needs to download a database from a link, heres the code I use to download the database adn save it on the sd card:

public void DownloadBD() {
    try {
        URL url = new URL(
                "http://mylink/dbHandler.axd?SqliteDbVersion=0");

        HttpURLConnection urlConnection = (HttpURLConnection) url
                .openConnection();

        urlConnection.setRequestMethod("GET");
        urlConnection.setDoOutput(true);
        urlConnection.connect();

        File SDCardRoot = Environment.getExternalStorageDirectory();
        File file = new File(SDCardRoot, "DirLaguna.db");

        FileOutputStream fileOutput = new FileOutputStream(file);

        InputStream inputStream = urlConnection.getInputStream();

        int totalSize = urlConnection.getContentLength();
        int downloadedSize = 0;

        byte[] buffer = new byte[1024];
        int bufferLength = 0;
        while ((bufferLength = inputStream.read(buffer)) > 0) {
            fileOutput.write(buffer, 0, bufferLength);
            downloadedSize += bufferLength;
        }
        fileOutput.close();
        location = file.getAbsolutePath();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Everything seems to work fine, but at the moment I want to query the database (I’m using raw querys) an error appears saying that the tables don’t exist.

After that, I tried debugging the application, and after that I get the error saying that the database is corrupted. I think that the downloading process is what is making the database corrupt.

Any help will be apreciated, if I’m missing some code to share please tell me so!

Thanks in advance!

  • 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-06-06T23:17:20+00:00Added an answer on June 6, 2026 at 11:17 pm

    1) The database you are downloading is sqlite database?

    2) If yes, then you need to copy that in your application before you start using it.

    The process will be something like you download the database in your Sd Card and as soon as its completed start copying it into your application so as it becomes part of your application, like this: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

    Make this happen in background by separate thread and then you are good to go and use it. Let me know if you face any problem or issue or I didn’t provided you info what you meant.

    Thanks

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

Sidebar

Related Questions

In my app I need to download several images from a server. I use
i am creating app which would download and save files, than user could use
I need help with NinePatchDrawable: My app can download themes from the network. Almost
My app needs to display a graphical representation of a value ranging from -1
i use sqlite database on my iphone app and i need to update this
I am creating an ios app that needs to download a html page and
I am trying to download database (SQLite) which has to be used in app.
I am working on an app where I need to download lots of images
My app needs feature to open iPhone/iPad Mail, contacts, Calendars settings panel and automatically
My app needs to have multiple screen e.g. one login page then another page

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.