• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Open Existing Database

ondrovic

Newbie
So I am downloading a pre made SQLite database and storing it on the /mnt/sdcard/database/db.db this file is downloading and saving correctly with the created tables and data but when trying to get the records from it, it's telling me there is no table bu there is anyone have any ideas?

here is my Database.java
Code:
package com.ondrovic.downloader;

import java.io.File;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;

public class Database extends SQLiteOpenHelper{
    //File rDIR = Environment.getExternalStorageDirectory();
    private static String DBPATH = "/data/databases/BOOMBOZZ/";
    private static String DBNAME = "boombozz.db";
    private static int DBVER = 1;
    
    private SQLiteDatabase db;
    private final Context dbContext;
    
    public Database(Context context) {
        super(context, DBNAME, null, DBVER);
        this.dbContext = context;
    }
    
    public void open() {
        String myPath = DBPATH + DBNAME;
        db = SQLiteDatabase.openDatabase(Environment.getExternalStorageDirectory() + myPath, null, SQLiteDatabase.OPEN_READWRITE);
    }
    
    public synchronized void close() {
        
        db.close();
        super.close();
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        
    }
}

Here is where I am calling it from my main.java
Code:
db = (new Database(this)).getWritableDatabase();

Thanks
 
can anyone post me and example of how to successfully copy a downloaded file to the internal /data/data/databases/ folder?

Or how to open a database that is stored on the SD card

Thanks
 
Back
Top Bottom