check Database Exist - Android Database

Android examples for Database:Table Exists

Description

check Database Exist

Demo Code


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class Main{
    //ww  w .  j a  va2  s  . c om
    public static boolean checkDatabaseExist(Context context) {
        SQLiteDatabase sqLiteDatabase = null;
        try {
            String fullPath = "your path";
            sqLiteDatabase = SQLiteDatabase.openDatabase(fullPath, null,
                    SQLiteDatabase.OPEN_READONLY);
        } catch (Exception e) {
        }
        if (sqLiteDatabase != null) {
            sqLiteDatabase.close();
        }
        return sqLiteDatabase != null ? true : false;
    }
}

Related Tutorials