Open Database by database path and name - Android Database

Android examples for Database:Database Open

Description

Open Database by database path and name

Demo Code


//package com.java2s;

import android.database.sqlite.SQLiteDatabase;

public class Main {
    private static String DB_PATH = "";
    private static SQLiteDatabase database = null;
    private static String DB_NAME = "";

    public static SQLiteDatabase getDatabase() {
        if (openDatabase())
            return database;
        else/*from   w ww .j  a  va  2s .c o  m*/
            return null;
    }

    private static boolean openDatabase() {
        String path = DB_PATH + DB_NAME;
        database = SQLiteDatabase.openDatabase(path, null,
                SQLiteDatabase.OPEN_READWRITE);
        return database != null;
    }
}

Related Tutorials