open Database by database file name - Android Database

Android examples for Database:Database Open

Description

open Database by database file name

Demo Code


//package com.java2s;

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.util.Log;

public class Main {
    public static SQLiteDatabase db;
    public static String dbname = "/storage/sdcard0/Handler.db";

    public static void openDatabase(String dbName) {
        try {/*from w ww  .  j a va2 s  .co  m*/
            db = SQLiteDatabase.openDatabase(dbname, null,
                    SQLiteDatabase.OPEN_READWRITE
                            + +SQLiteDatabase.CREATE_IF_NECESSARY);
            Log.d("DataBase open ", "open");
        } catch (SQLiteException ex) {
            //Toast.makeText(this, ex.getMessage(), 1).show();
            Log.d("DataBase open fail", "fail");
        }
    }
}

Related Tutorials