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


Java SQLiteDatabase.openOrCreateDatabase方法代码示例

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


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

示例1: doOpenOrCreateDb

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void doOpenOrCreateDb(final File databaseFile) {
    if (StorageManager.InternalStorageProvider.ID.equals(mStorageProviderId)) {
        // internal storage
        mDb = context.openOrCreateDatabase(databaseFile.getName(), Context.MODE_PRIVATE,
                null);
    } else {
        // external storage
        mDb = SQLiteDatabase.openOrCreateDatabase(databaseFile, null);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:11,代码来源:LockableDatabase.java

示例2: searchCity

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * 通过名字或者拼音搜索
 *
 * @param keyword
 * @return
 */
public List<City> searchCity(final String keyword) {
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
    Cursor cursor = db.rawQuery("select * from " + TABLE_NAME + " where name like \"%" + keyword
            + "%\" or pinyin like \"%" + keyword + "%\"", null);
    List<City> result = new ArrayList<City>();
    City city;
    while (cursor.moveToNext()) {
        String name = cursor.getString(cursor.getColumnIndex(NAME));
        String pinyin = cursor.getString(cursor.getColumnIndex(PINYIN));
        city = new City(name, pinyin);
        result.add(city);
    }
    cursor.close();
    db.close();
    Collections.sort(result, new CityComparator());
    return result;
}
 
开发者ID:shenhuanet,项目名称:AndroidOpen,代码行数:24,代码来源:DBManager.java

示例3: createDbFileOnSDCard

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * 在SD卡的指定目录上创建文件
 * 
 * @param sdcardPath
 * @param dbfilename
 * @return
 */
private SQLiteDatabase createDbFileOnSDCard(String sdcardPath,
		String dbfilename) {
	File dbf = new File(sdcardPath, dbfilename);
	LogUtils.info("dbf.getAbsolutePath():" + dbf.getAbsolutePath());
	if (!dbf.exists()) {
		try {
			if (dbf.createNewFile()) {
				return SQLiteDatabase.openOrCreateDatabase(dbf, null);
			}
		} catch (IOException ioex) {
			throw new DbException("数据库文件创建失败", ioex);
		}
	} else {
		return SQLiteDatabase.openOrCreateDatabase(dbf, null);
	}

	return null;
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:26,代码来源:FinalDb.java

示例4: setDBManager

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public SQLiteDatabase setDBManager(String packName) {
    @SuppressLint("SdCardPath") String dbPath = "/data/data/" + packName + "/databases/" + DB_NAME;
    if (!new File(dbPath).exists()) {
        try {
            FileOutputStream out = new FileOutputStream(dbPath);
            InputStream in = mContext.getAssets()
                    .open(DB_NAME);
            byte[] buffer = new byte[1024];
            int readBytes;
            while ((readBytes = in.read(buffer)) != -1)
                out.write(buffer,
                        0,
                        readBytes);
            in.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();


        }
    }


    return SQLiteDatabase.openOrCreateDatabase(dbPath,
            null);
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:27,代码来源:ExternalDBManager.java

示例5: getAllCities

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * 读取所有城市
 *
 * @return
 */
public List<City> getAllCities() {
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
    Cursor cursor = db.rawQuery("select * from " + TABLE_NAME, null);
    List<City> result = new ArrayList<City>();
    City city;
    while (cursor.moveToNext()) {
        String name = cursor.getString(cursor.getColumnIndex(NAME));
        String pinyin = cursor.getString(cursor.getColumnIndex(PINYIN));
        city = new City(name, pinyin);
        result.add(city);
    }
    cursor.close();
    db.close();
    Collections.sort(result, new CityComparator());
    return result;
}
 
开发者ID:shenhuanet,项目名称:AndroidOpen,代码行数:22,代码来源:DBManager.java

示例6: getUsableDataBase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Returns a usable database with the given name. If a database with this name
 * already exists, it is returned. Otherwise created with the given SQL create
 * query.
 */
protected static SQLiteDatabase getUsableDataBase(String dbName,
    String sqlCreateQuery) {
  File dbFile = getPathToDb(dbName);

  File fileDirectory = new File(dbFile.getParent());
  if (!fileDirectory.exists()) {
    // Make sure the path for the file exists, before creating the
    // database.
    fileDirectory.mkdirs();
  }
  Log.d(TAG, "DB Path: " + dbFile.getAbsolutePath());
  boolean initDb = !dbFile.exists();
  try {
    SQLiteDatabase result = SQLiteDatabase.openOrCreateDatabase(dbFile, null);

    if (initDb) {
      result.execSQL(sqlCreateQuery);
    }

    return result;
  } catch (SQLiteException ex) {
    Log.w(TAG, "Could not open or image database.");
    return null;
  }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:31,代码来源:AbstractPicViewDatabase.java

示例7: createDataBase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void createDataBase() throws IOException {
	boolean dbExist = checkDataBase();
	if (dbExist) {
		// 数据库已存在,do nothing.
	} else {
		// 创建数据库
		try {
			File dir = new File(DB_PATH);
			if (!dir.exists()) {
				dir.mkdirs();
			}
			File dbf = new File(DB_PATH + DB_NAME);
			if (dbf.exists()) {
				dbf.delete();
			}
			//通过openOrCreateDatabase方法将assets目录下的数据库,创建到系统默认的地方
			SQLiteDatabase.openOrCreateDatabase(dbf, null);
			// 复制asseets中的db文件到DB_PATH下
			copyDataBase();
		} catch (IOException e) {
			throw new Error("数据库创建失败");
		}
	}
}
 
开发者ID:jacksenh,项目名称:CitySelct,代码行数:25,代码来源:AllCitySqliteOpenHelper.java

示例8: ce

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void ce() {
    SQLiteDatabase openOrCreateDatabase;
    try {
        openOrCreateDatabase = SQLiteDatabase.openOrCreateDatabase(this.iB, null);
    } catch (Exception e) {
        openOrCreateDatabase = null;
    }
    if (openOrCreateDatabase != null) {
        long queryNumEntries = DatabaseUtils.queryNumEntries(openOrCreateDatabase, "wof");
        long queryNumEntries2 = DatabaseUtils.queryNumEntries(openOrCreateDatabase, "bdcltb09");
        boolean z = queryNumEntries > 10000;
        boolean z2 = queryNumEntries2 > 10000;
        if (z || z2) {
            new a().execute(new Boolean[]{Boolean.valueOf(z), Boolean.valueOf(z2)});
        }
        openOrCreateDatabase.close();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:ay.java

示例9: cg

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void cg() {
    try {
        File file = new File(I);
        File file2 = new File(this.iB);
        if (!file.exists()) {
            file.mkdirs();
        }
        if (!file2.exists()) {
            file2.createNewFile();
        }
        if (file2.exists()) {
            SQLiteDatabase openOrCreateDatabase = SQLiteDatabase.openOrCreateDatabase(file2, null);
            openOrCreateDatabase.execSQL("CREATE TABLE IF NOT EXISTS bdcltb09(id CHAR(40) PRIMARY KEY,time DOUBLE,tag DOUBLE, type DOUBLE , ac INT);");
            openOrCreateDatabase.execSQL("CREATE TABLE IF NOT EXISTS wof(id CHAR(15) PRIMARY KEY,mktime DOUBLE,time DOUBLE, ac INT, bc INT, cc INT);");
            openOrCreateDatabase.setVersion(1);
            openOrCreateDatabase.close();
        }
    } catch (Exception e) {
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:ay.java

示例10: onCreate

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // 初始化在线数据库
    // OnlineDatabase.connect(this.getResources().getString(R.string.DataBaseUrl));
    LocalDatabase=SQLiteDatabase.openOrCreateDatabase(this.getFilesDir().toString()+"/studentinfo.db3",null);
    background_task task=new background_task(this);
    task.execute();
}
 
开发者ID:mikecovlee,项目名称:StudentInfoClient,代码行数:11,代码来源:MainActivity.java

示例11: openOrCreateDatabase

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private SQLiteDatabase openOrCreateDatabase(DaoConfig config) {
    SQLiteDatabase result = null;

    File dbDir = config.getDbDir();
    if (dbDir != null && (dbDir.exists() || dbDir.mkdirs())) {
        File dbFile = new File(dbDir, config.getDbName());
        result = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
    } else {
        result = x.app().openOrCreateDatabase(config.getDbName(), 0, null);
    }
    return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:DbManagerImpl.java

示例12: SQLiteToExcel

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public SQLiteToExcel(Context context, String dbName, String exportPath) {
    mContext = context;
    mDbName = dbName;
    mExportPath = exportPath;
    try {
        database = SQLiteDatabase.openOrCreateDatabase(mContext.getDatabasePath(mDbName).getAbsolutePath(), null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:androidmads,项目名称:SQLite2XL,代码行数:11,代码来源:SQLiteToExcel.java

示例13: BaseDaoFactory

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private BaseDaoFactory() {
    if (TextUtils.isEmpty(mDbPath)) {
        throw new RuntimeException("在使用BaseDaoFactory之前,请调用BaseDaoFactory.init()初始化好数据库路径。");
    }
    // 打开数据库,得到数据库对象
    mDatabase = SQLiteDatabase.openOrCreateDatabase(mDbPath, null);
}
 
开发者ID:GitLqr,项目名称:SimpleDbFrame,代码行数:8,代码来源:BaseDaoFactory.java

示例14: r

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void r(String str) {
    SQLiteDatabase sQLiteDatabase = null;
    if (str != null && !str.equals(this.iG)) {
        try {
            sQLiteDatabase = SQLiteDatabase.openOrCreateDatabase(this.iB, null);
        } catch (Exception e) {
        }
        if (sQLiteDatabase == null || str == null) {
            this.iy = false;
            return;
        }
        this.iy = false;
        try {
            Cursor rawQuery = sQLiteDatabase.rawQuery("select * from bdcltb09 where id = \"" + str + "\";", null);
            this.iG = str;
            this.ip = System.currentTimeMillis();
            if (rawQuery != null) {
                if (rawQuery.moveToFirst()) {
                    this.iv = rawQuery.getDouble(1) - 1235.4323d;
                    this.iz = rawQuery.getDouble(2) - 4326.0d;
                    this.iu = rawQuery.getDouble(3) - 2367.3217d;
                    this.iy = true;
                }
                rawQuery.close();
            }
        } catch (Exception e2) {
        }
        sQLiteDatabase.close();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:31,代码来源:ay.java

示例15: ExcelToSQLite

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public ExcelToSQLite(Context context, String dbName, boolean dropTable) {
    mContext = context;
    mDbName = dbName;
    this.dropTable = dropTable;
    try {
        database = SQLiteDatabase.openOrCreateDatabase(mContext.getDatabasePath(mDbName).getAbsolutePath(), null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:androidmads,项目名称:SQLite2XL,代码行数:11,代码来源:ExcelToSQLite.java


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