当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteDatabase.openDatabase方法代码示例

本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.openDatabase方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.openDatabase方法的具体用法?Java SQLiteDatabase.openDatabase怎么用?Java SQLiteDatabase.openDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.sqlite.SQLiteDatabase的用法示例。


在下文中一共展示了SQLiteDatabase.openDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ApnDatabase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private ApnDatabase(final Context context) throws IOException {
  this.context = context;

  File dbFile = context.getDatabasePath(DATABASE_NAME);

  if (!dbFile.getParentFile().exists() && !dbFile.getParentFile().mkdir()) {
    throw new IOException("couldn't make databases directory");
  }

  Util.copy(context.getAssets().open(ASSET_PATH, AssetManager.ACCESS_STREAMING),
            new FileOutputStream(dbFile));

  try {
    this.db = SQLiteDatabase.openDatabase(context.getDatabasePath(DATABASE_NAME).getPath(),
                                          null,
                                          SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
  } catch (SQLiteException e) {
    throw new IOException(e);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:21,代码来源:ApnDatabase.java

示例2: openDB

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Function to open connection with database
 *
 * @param path database path in mobile
 * @return database object to start queries
 */
public SQLiteDatabase openDB(String path) {

    Log.d("DATABASE", path);

    SQLiteDatabase db = null;
    try {
        db = SQLiteDatabase.openDatabase(path, null, 0);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    return db;

}
 
开发者ID:fekracomputers,项目名称:QuranAndroid,代码行数:22,代码来源:DatabaseAccess.java

示例3: DatabaseHandler

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private DatabaseHandler(Context context, String databaseName) throws SQLException {
  String base = QuranFileUtils.getQuranDatabaseDirectory(context);
  if (base == null) return;
  String path = base + File.separator + databaseName;
  Crashlytics.log("opening database file: " + path);
  try {
    database = SQLiteDatabase.openDatabase(path, null,
      SQLiteDatabase.NO_LOCALIZED_COLLATORS, new DefaultDatabaseErrorHandler());
  } catch (SQLiteDatabaseCorruptException sce) {
    Crashlytics.log("corrupt database: " + databaseName);
    throw sce;
  } catch (SQLException se){
    Crashlytics.log("database file " + path +
        (new File(path).exists()? " exists" : " doesn't exist"));
    throw se;
  }

  schemaVersion = getSchemaVersion();
  matchString = "<font color=\"" +
      ContextCompat.getColor(context, R.color.translation_highlight) +
      "\">";
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:23,代码来源:DatabaseHandler.java

示例4: checkDataBase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Check if the database already exist to avoid re-copying the file each time you open the application.
 *
 * ToDo: NOTE:  This is a dumb check, as it currently only tries to open it.
 *              It may be other reasons why it can't be opened even if it already exists.
 *
 * @return true if it exists, false if it doesn't
 */
private boolean checkDataBase() {

    SQLiteDatabase checkDB = null;
    try {
        Log.i(TAG, mTAG + "Checking if DB exists...");
        checkDB = SQLiteDatabase.openDatabase(mDatabasePath, null, SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
        Log.i(TAG, mTAG + "SQL Exception! Database can\'t be opened: " + e);
        //Log.i(TAG, mTAG + "Database not yet created: " + e);
    }

    if (checkDB != null) {
        checkDB.close();
        Log.i(TAG, mTAG + "OK (found)");
        return true;
    }
    Log.i(TAG, mTAG + "Database probably not yet created.");
    return false;
}
 
开发者ID:5GSD,项目名称:AIMSICDL,代码行数:28,代码来源:AIMSICDDbAdapter.java

示例5: getReadableDatabase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Create and/or open a database.  This will be the same object returned by
 * {@link #getWritableDatabase} unless some problem, such as a full disk,
 * requires the database to be opened read-only.  In that case, a read-only
 * database object will be returned.  If the problem is fixed, a future call
 * to {@link #getWritableDatabase} may succeed, in which case the read-only
 * database object will be closed and the read/write object will be returned
 * in the future.
 *
 * <p class="caution">Like {@link #getWritableDatabase}, this method may
 * take a long time to return, so you should not call it from the
 * application main thread, including from
 * {@link android.content.ContentProvider#onCreate ContentProvider.onCreate()}.
 *
 * @return a database object valid until {@link #getWritableDatabase}
 * or {@link #close} is called.
 * @throws SQLiteException if the database cannot be opened
 */
@Override
public synchronized SQLiteDatabase getReadableDatabase() {
    if (mDatabase != null && mDatabase.isOpen()) {
        return mDatabase;  // The database is already open for business
    }

    if (mIsInitializing) {
        throw new IllegalStateException("getReadableDatabase called recursively");
    }

    try {
        return getWritableDatabase();
    } catch (SQLiteException e) {
        if (mName == null) throw e;  // Can't open a temp database read-only!
        Log.e(TAG, "Couldn't open " + mName + " for writing (will try read-only):", e);
    }

    SQLiteDatabase db = null;
    try {
        mIsInitializing = true;
        String path = mContext.getDatabasePath(mName).getPath();
        db = SQLiteDatabase.openDatabase(path, mFactory, SQLiteDatabase.OPEN_READONLY);
        if (db.getVersion() != mNewVersion) {
            throw new SQLiteException("Can't upgrade read-only database from version " +
                    db.getVersion() + " to " + mNewVersion + ": " + path);
        }

        onOpen(db);
        Log.w(TAG, "Opened " + mName + " in read-only mode");
        mDatabase = db;
        return mDatabase;
    } finally {
        mIsInitializing = false;
        if (db != null && db != mDatabase) db.close();
    }
}
 
开发者ID:albertogiunta,项目名称:justintrain-client-android,代码行数:55,代码来源:SQLiteAssetHelper.java

示例6: returnDatabase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private SQLiteDatabase returnDatabase() {
    try {
        SQLiteDatabase db = SQLiteDatabase.openDatabase(mDatabasePath + "/" + mName, mFactory, SQLiteDatabase.OPEN_READWRITE);
        Log.i(TAG, "successfully opened database " + mName);
        return db;
    } catch (SQLiteException e) {
        Log.w(TAG, "could not open database " + mName + " - " + e.getMessage());
        return null;
    }
}
 
开发者ID:albertogiunta,项目名称:justintrain-client-android,代码行数:11,代码来源:SQLiteAssetHelper.java

示例7: openDataBase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@SuppressWarnings("unused")
   public void openDataBase() throws SQLException {

	// Open the database
	myDataBase = SQLiteDatabase.openDatabase(mDBFileName, null,
			SQLiteDatabase.OPEN_READONLY);

}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:9,代码来源:DataBaseHelper.java

示例8: AyahInfoDatabaseHandler

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private AyahInfoDatabaseHandler(Context context, String databaseName) throws SQLException {
  String base = QuranFileUtils.getQuranAyahDatabaseDirectory(context);
  if (base == null) {
    database = null;
  } else {
    String path = base + File.separator + databaseName;
    database = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
  }
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:10,代码来源:AyahInfoDatabaseHandler.java

示例9: SuraTimingDatabaseHandler

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private SuraTimingDatabaseHandler(String path) throws SQLException {
  Crashlytics.log("opening gapless data file, " + path);
  try {
    mDatabase = SQLiteDatabase.openDatabase(path, null,
        SQLiteDatabase.NO_LOCALIZED_COLLATORS, new DefaultDatabaseErrorHandler());
  } catch (SQLiteDatabaseCorruptException sce) {
    Crashlytics.log("database corrupted: " + path);
    mDatabase = null;
  } catch (SQLException se) {
    Crashlytics.log("database at " + path +
        (new File(path).exists() ? " exists" : " doesn't exist"));
    Crashlytics.logException(se);
    mDatabase = null;
  }
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:16,代码来源:SuraTimingDatabaseHandler.java

示例10: AIMSICDDbAdapter

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public AIMSICDDbAdapter(Context context) {
    super(context, DB_NAME, null, 1);
    mContext = context;
    mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    mDatabasePath = mContext.getDatabasePath(DB_NAME).getAbsolutePath();
    mExternalFilesDirPath = mContext.getExternalFilesDir(null) + File.separator;
    //e.g. /storage/emulated/0/Android/data/zz.aimsicd.lite/

    // Create a new blank DB then write pre-compiled DB in assets folder to blank DB.
    // This will throw error on first create because there is no DB to open and this is normal.
    createDataBase();

    //return writable database
    mDb = SQLiteDatabase.openDatabase(mDatabasePath, null, SQLiteDatabase.OPEN_READWRITE);

    // This will return the database as open so we don't need to use .open . Then when app
    // is exiting we use new AIMSICDDbAdapter(getApplicationContext()).close(); to close it
    this.getWritableDatabase();
    mTables = new String[]{

            // I am trying to keep in same order and aimsicd.sql script
            // Only backing up useful tables, uncomment if you want to backup
            DBTableColumnIds.DEFAULT_LOCATION_TABLE_NAME,   // defaultLocation:     Default MCC for each country
            //DBTableColumnIds.API_KEYS_TABLE_NAME,         // API_keys:            API keys for OpenCellID, MLS etc.
            //DBTableColumnIds.COUNTER_MEASURES_TABLE_NAME, // CounterMeasures:     Counter Measures thresholds and description
            //DBTableColumnIds.DBE_CAPABILITIES_TABLE_NAME, // DBe_capabilities:    External: MNO & BTS network capabilities
            DBTableColumnIds.DBE_IMPORT_TABLE_NAME,         // DBe_import:          External: BTS import table
            DBTableColumnIds.DBI_BTS_TABLE_NAME,            // DBi_bts:             Internal: (physical) BTS data
            DBTableColumnIds.DBI_MEASURE_TABLE_NAME,        // DBi_measure:         Internal: (volatile) network measurements
            //DBTableColumnIds.DETECTION_FLAGS_TABLE_NAME,  // DetectionFlags:      Detection Flag description, settings and scoring table
            DBTableColumnIds.EVENTLOG_TABLE_NAME,           //                      Detection and general EventLog (persistent)
            //DBTableColumnIds.SECTOR_TYPE_TABLE_NAME,      // SectorType:          BTS tower sector configuration (Many CID, same BTS)
            DBTableColumnIds.DETECTION_STRINGS_TABLE_NAME,  //                      Detection strings to will be picked up in logcat
            DBTableColumnIds.SMS_DATA_TABLE_NAME,           //                      Silent SMS details
    };
}
 
开发者ID:5GSD,项目名称:AIMSICDL,代码行数:37,代码来源:AIMSICDDbAdapter.java

示例11: SQLHelper

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public SQLHelper(String _dbFilePath, DatabaseErrorHandler errHandler) {
    this.mCurDBFilePath = _dbFilePath;
    try {
        _db = SQLiteDatabase.openDatabase(mCurDBFilePath, null, 0, errHandler);
        isDataBase = true;
    } catch (Exception e) {
        isDataBase = false;
    }
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:10,代码来源:SQLHelper.java

示例12: openDataBase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean openDataBase(String strDBName) throws SQLException
{
    String mPath = DB_PATH + strDBName;
    //Log.v("mPath", mPath);
    mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.CREATE_IF_NECESSARY);
    //mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
    return mDataBase != null;
}
 
开发者ID:JW1992,项目名称:NISTGammaSearch,代码行数:9,代码来源:DataBaseHelper.java

示例13: openDataBase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void openDataBase() throws SQLException {
  // Open the database
  String myPath = DB_PATH + DB_NAME;
  myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
}
 
开发者ID:UshalNaidoo,项目名称:Android-Bubble-Game,代码行数:6,代码来源:DataBaseHelper.java

示例14: openDataBase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
boolean openDataBase() throws SQLException {
    mDataBase = SQLiteDatabase.openDatabase(DB_PATH, null, SQLiteDatabase.CREATE_IF_NECESSARY);
    return mDataBase != null;
}
 
开发者ID:shanraisshan,项目名称:Android-Copy-Database,代码行数:5,代码来源:DBHelper.java

示例15: openDataBase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean openDataBase() throws SQLException {
    mDataBase = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, SQLiteDatabase.CREATE_IF_NECESSARY);
    return mDataBase != null;
}
 
开发者ID:Harrix,项目名称:uchimznaem-helper,代码行数:5,代码来源:DatabaseHelper.java


注:本文中的android.database.sqlite.SQLiteDatabase.openDatabase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。