本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.close方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.close方法的具体用法?Java SQLiteDatabase.close怎么用?Java SQLiteDatabase.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.sqlite.SQLiteDatabase
的用法示例。
在下文中一共展示了SQLiteDatabase.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertLocation
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void insertLocation(Location loc) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Constants.DATABASE.LOCATION_NAME, loc.getLoactionName());
values.put(Constants.DATABASE.LOCATION_TYPE, loc.getLocationType());
values.put(Constants.DATABASE.LOCATION_STICKER_UUID, loc.getStickerUuid());
values.put(Constants.DATABASE.LOCATION_X, loc.getLocationX());
values.put(Constants.DATABASE.LOCATION_Y, loc.getLocationY());
values.put(Constants.DATABASE.LOCATION_COOR_X, loc.getCoordinateX());
values.put(Constants.DATABASE.LOCATION_COOR_Y, loc.getCoordinateY());
values.put(Constants.DATABASE.LOCATION_FLOOR_ID, loc.getFloorId());
db.insert(Constants.DATABASE.LOCATION_TABLE_NAME, null, values);
values.clear();
db.close();
}
示例2: loadPlaylist
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public List<MusicBean> loadPlaylist(int playlistID) {
SQLiteDatabase db = mDBHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select name,singer,album,duration,diskMusic.[path] from diskMusic left join playlist_detail on playlist_detail.[path]=diskMusic.[path] where playlist_detail.[list_id]=? order by playlist_detail.[path] desc; "
,new String[]{String.valueOf(playlistID)});
ArrayList<MusicBean> list = new ArrayList<>();
while (null != cursor && cursor.moveToNext()) {
String name = cursor.getString(0);
String singer = cursor.getString(1);
String album = cursor.getString(2);
long duration = cursor.getLong(3);
String path = cursor.getString(4);
list.add(new MusicBean(name,singer,album,duration, path));
}
if (cursor != null) {
cursor.close();
}
db.close();
return list;
}
示例3: getResultCityList
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void getResultCityList(String keyword) {
AllCitySqliteOpenHelper dbHelper = new AllCitySqliteOpenHelper(this);
try {
dbHelper.createDataBase();
SQLiteDatabase db = dbHelper.getWritableDatabase();
Cursor cursor = db.rawQuery(
"select * from city where name like \"%" + keyword
+ "%\" or pinyin like \"%" + keyword + "%\"", null);
City city;
while (cursor.moveToNext()) {
String cityName=cursor.getString(cursor.getColumnIndex("name"));
String cityPinyin=cursor.getString(cursor.getColumnIndex("pinyin"));
city = new City(cityName,cityPinyin);
searchCityList.add(city);
}
cursor.close();
db.close();
} catch (IOException e) {
e.printStackTrace();
}
//将得到的集合按照自定义的comparator的规则进行排序
Collections.sort(searchCityList, comparator);
}
示例4: updateUI
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void updateUI() {
ArrayList<String> objList = new ArrayList<>();
ArrayList<Integer> numList = new ArrayList<>();
SQLiteDatabase db = mHelper.getReadableDatabase();
Cursor cursor = db.query(TaskContract.TaskEntry.TABLE,
new String[]{TaskContract.TaskEntry._ID, TaskContract.TaskEntry.COL_TASK_TITLE, TaskContract.TaskEntry.COL_NUM_TITLE},
null, null, null, null, null);
while (cursor.moveToNext()) {
int idx = cursor.getColumnIndex(TaskContract.TaskEntry.COL_TASK_TITLE);
int idx_num = cursor.getColumnIndex(TaskContract.TaskEntry.COL_NUM_TITLE);
objList.add(cursor.getString(idx));
numList.add(cursor.getInt(idx_num));
}
mListAdapter.setData(objList, numList);
cursor.close();
db.close();
if (objList.size() > 0) {
instructionTextView.setVisibility(View.INVISIBLE);
}else {
instructionTextView.setVisibility(View.VISIBLE);
}
}
示例5: save
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static void save(String key, boolean value) {
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = new SQLiteHelper(App.getContext()).getReadableDatabase();
cursor = db.rawQuery("select * from temp where key=? ", new String[]{key});
ContentValues contentValues = new ContentValues();
contentValues.put("key", key);
contentValues.put("value", value);
if (cursor.moveToFirst()) {
db.update("temp", contentValues, "key=?", new String[]{key});
} else {
db.insert("temp", null, contentValues);
}
} finally {
if (cursor != null)
cursor.close();
if (db != null)
db.close();
}
}
示例6: loadDaily
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public List<DailyPvDatum> loadDaily(int year, int month) {
SQLiteDatabase db = pvDataHelper.getReadableDatabase();
String[] projection = {
PvDataContract.DailyPvData.COLUMN_NAME_DAY,
PvDataContract.DailyPvData.COLUMN_NAME_ENERGY_GENERATED,
PvDataContract.DailyPvData.COLUMN_NAME_PEAK_POWER,
PvDataContract.DailyPvData.COLUMN_NAME_CONDITION
};
String sortOrder =
PvDataContract.DailyPvData.COLUMN_NAME_DAY + " ASC";
String selection =
PvDataContract.DailyPvData.COLUMN_NAME_YEAR + "=? AND " +
PvDataContract.DailyPvData.COLUMN_NAME_MONTH + "=?";
String[] selectionArgs = {
"" + year,
"" + month
};
List<DailyPvDatum> dailyPvData = new ArrayList<>();
Cursor cursor = db.query(PvDataContract.DailyPvData.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
dailyPvData.add(new DailyPvDatum(
year,
month,
cursor.getInt(cursor.getColumnIndex(PvDataContract.DailyPvData.COLUMN_NAME_DAY)),
cursor.getDouble(cursor.getColumnIndex(PvDataContract.DailyPvData.COLUMN_NAME_ENERGY_GENERATED)),
cursor.getDouble(cursor.getColumnIndex(PvDataContract.DailyPvData.COLUMN_NAME_PEAK_POWER)),
cursor.getString(cursor.getColumnIndex(PvDataContract.DailyPvData.COLUMN_NAME_CONDITION))));
} while (cursor.moveToNext());
}
cursor.close();
}
db.close();
Log.d(TAG, "Loaded " + dailyPvData.size() + " rows of daily PV data for " + DateTimeUtils.formatYearMonth(year, month, true) + " from database");
return dailyPvData;
}
示例7: checkGroupExist
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public int checkGroupExist(int gUid, GroupBean gb) {
try {
String exist = "SELECT COUNT(*) as m FROM " + TABLE_NAME + " Where " + T_GROUPID + " = " + gUid;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(exist, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
//Log.e("ddd "," Exist "+cursor.getInt(0));
if (cursor.getInt(0) != 0) {
//String updateTable= "UPDATE "+TABLE_NAME+" SET "+T_TAGNAME+"= '"+gb.getmGroupTag().trim()+"', "+T_DESCRITION+"= '"+gb.getmGroupTag().trim()+"', "+T_GROUPPHOTO+"= '"+gb.getmPhoto().trim()+"', "+T_MEMBERCOUNT+"= '"+String.valueOf(gb.getmGroupSize())+"', "+T_ADMINFLAG+"= '"+gb.getmGroupAdmin()+" Where "+T_GROUPID+" = "+gUid+";";
ContentValues cv = new ContentValues();
cv.put(T_TAGNAME, gb.getmGroupTag().trim());
cv.put(T_DESCRITION, gb.getmGroupDesc().trim());
cv.put(T_GROUPPHOTO, gb.getmPhoto().trim());
cv.put(T_MEMBERCOUNT, String.valueOf(gb.getmGroupSize()));
cv.put(T_ADMINFLAG, gb.getmGroupAdmin());
cv.put(T_CREATEUPDATETS, gb.getmGroupCreatedDate());
db.update(TABLE_NAME, cv, T_GROUPID + " = ?",
new String[]{String.valueOf(gb.getmGroupId())});
return 0;
} else {
addGroup(gb);
}
} while (cursor.moveToNext());
}
if (cursor != null)
cursor.close();
db.close();
} catch (Exception e) {
// TODO: handle exception
//Log.e("GroupDBErro", "FetchAllDB " + e.getMessage());
e.printStackTrace();
}
return 1;
}
示例8: addGroup
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public int addGroup(GroupBean gb) {
//Log.e("ADD GROUP", "ADD GROUP");
int status = 0;
try {
SQLiteDatabase sq = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(T_GROUPID, Integer.parseInt(gb.getmGroupId().trim()));
cv.put(T_GROUPNAME, gb.getmGroupName().trim());
cv.put(T_MADEBYNAME, gb.getmGroupMadeByName().trim());
cv.put(T_MADEBYPHONENO, gb.getmGroupMadeByNum().trim());
cv.put(T_TAGNAME, gb.getmGroupTag().trim());
cv.put(T_DESCRITION, gb.getmGroupDesc().trim());
cv.put(T_GROUPPHOTO, gb.getmPhoto().trim());
cv.put(T_MEMBERCOUNT, String.valueOf(gb.getmGroupSize()));
cv.put(T_ACCESS_TYPE, gb.getmGroupAccessType().trim());
cv.put(T_ADMINFLAG, gb.getmGroupAdmin());
cv.put(T_CREATEUPDATETS, gb.getmGroupCreatedDate());
sq.insert(TABLE_NAME, null, cv);
status = 1;
sq.close();
} catch (Exception e) {
// TODO: handle exception
status = 0;
//Log.e("GroupDBErro", "AddGroup "+e.getMessage());
e.printStackTrace();
}
return status;
}
示例9: checkDataBase
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* 检测数据库是否存在并且能否打开
*/
private boolean checkDataBase() {
SQLiteDatabase checkDB = null;
try {
String myPath = CopyDBApplication.DBPATH + CopyDBApplication.DBNAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
} catch (Exception e) {
}
if (checkDB != null) {
checkDB.close();
}
return checkDB != null ? true : false;
}
示例10: getWifiServer
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public WifiServer getWifiServer(long id){
SQLiteDatabase db = this.getReadableDatabase();
WifiServer wifiServer = new WifiServer();
wifiServer.setId(id);
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLE_SERVERS +
" JOIN " + TABLE_WIFI_SERVERS +
" USING(" + COLUMN_ID + ")");
Cursor c = qb.query(db,
new String[]{COLUMN_IS_ENABLED,
COLUMN_CERTIFICATE_ID,
COLUMN_IP_OR_HOSTNAME,
COLUMN_PORT_NUMBER,
COLUMN_SSID_WHITELIST},
COLUMN_ID + "=?", new String[]{String.valueOf(id)},
null, null, null);
if (c.moveToFirst()){
wifiServer.setIsEnabled(intToBool(c.getInt(0)));
wifiServer.setCertificateId(c.getLong(1));
wifiServer.setIpOrHostname(c.getString(2));
wifiServer.setPortNumber(c.getInt(3));
wifiServer.setSsidWhitelist(c.getString(4));
}
c.close();
db.close();
return wifiServer;
}
示例11: DatabaseReadableClose
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* ********************DB属性操作************************
*/
public void DatabaseReadableClose(SQLiteDatabase database) {
try {
database.close();
this.isDBReading = false;
} catch (Exception exception) {
Log.e(TAG, ": [DB Exception->]" + exception.getMessage());
}
}
示例12: getAllGroup
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public ArrayList<GroupBean> getAllGroup() {
ArrayList<GroupBean> gbList = new ArrayList<GroupBean>();
try {
String selectQuery = "SELECT " + T_GROUPID + ", " + T_GROUPNAME + ", " + T_MADEBYNAME +
", " + T_MADEBYPHONENO + ", " + T_TAGNAME + ", " + T_DESCRITION + ", " + T_GROUPPHOTO + ", " +
T_MEMBERCOUNT + ", " + T_ACCESS_TYPE + ", " + T_ADMINFLAG + ", " + T_CREATEUPDATETS + " FROM " + TABLE_NAME;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
GroupBean contact = new GroupBean();
contact.setmGroupId(String.valueOf(cursor.getInt(0)));
contact.setmGroupName(cursor.getString(1));
contact.setmGroupMadeByName(cursor.getString(2));
contact.setmGroupMadeByNum(cursor.getString(3));
contact.setmGroupTag(cursor.getString(4));
contact.setmGroupDesc(cursor.getString(5));
contact.setmPhoto(cursor.getString(6));
contact.setmGroupSize(Integer.parseInt(cursor.getString(7).trim()));
contact.setmGroupAccessType(cursor.getString(8));
contact.setmGroupAdmin(cursor.getString(9));
contact.setmGroupCreatedDate(cursor.getString(10));
gbList.add(contact);
} while (cursor.moveToNext());
}
if (cursor != null)
cursor.close();
db.close();
} catch (Exception e) {
// TODO: handle exception
//Log.e("GroupDBErro", "FetchAllDB " + e.getMessage());
e.printStackTrace();
}
return gbList;
}
示例13: addContact
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addContact(Friends contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, contact.getName()); // Contact Name
values.put(KEY_DNAME, contact.getNameD());
values.put(KEY_DDNAME, contact.getNameDD());
// Inserting Row
db.insert(TABLE_CONTACTS, null, values);
db.close(); // Closing database connection
}
示例14: saveOffer
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@NonNull
public synchronized void saveOffer(@NonNull String offerToken) {
final SQLiteDatabase db = getWritableDatabase();
db.insert(OfferConsuptionTable.TABLE_NAME, null, OfferConsuptionTable.convertToContentValues(offerToken, null));
db.close();
}
示例15: testBasicWeatherQuery
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* This test uses the database directly to insert a row of test data and then uses the
* ContentProvider to read out the data. We access the database directly to insert the data
* because we are testing our ContentProvider's query functionality. If we wanted to use the
* ContentProvider's insert method, we would have to assume that that insert method was
* working, which defeats the point of testing.
* <p>
* If this test fails, you should check the logic in your
* {@link WeatherProvider#insert(Uri, ContentValues)} and make sure it matches up with our
* solution code.
* <p>
* Potential causes for failure:
* <p>
* 1) There was a problem inserting data into the database directly via SQLite
* <p>
* 2) The values contained in the cursor did not match the values we inserted via SQLite
*/
@Test
public void testBasicWeatherQuery() {
/* Use WeatherDbHelper to get access to a writable database */
WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);
SQLiteDatabase database = dbHelper.getWritableDatabase();
/* Obtain weather values from TestUtilities */
ContentValues testWeatherValues = TestUtilities.createTestWeatherContentValues();
/* Insert ContentValues into database and get a row ID back */
long weatherRowId = database.insert(
/* Table to insert values into */
WeatherContract.WeatherEntry.TABLE_NAME,
null,
/* Values to insert into table */
testWeatherValues);
String insertFailed = "Unable to insert into the database";
assertTrue(insertFailed, weatherRowId != -1);
/* We are done with the database, close it now. */
database.close();
/*
* Perform our ContentProvider query. We expect the cursor that is returned will contain
* the exact same data that is in testWeatherValues and we will validate that in the next
* step.
*/
Cursor weatherCursor = mContext.getContentResolver().query(
WeatherContract.WeatherEntry.CONTENT_URI,
/* Columns; leaving this null returns every column in the table */
null,
/* Optional specification for columns in the "where" clause above */
null,
/* Values for "where" clause */
null,
/* Sort order to return in Cursor */
null);
/* This method will ensure that we */
TestUtilities.validateThenCloseCursor("testBasicWeatherQuery",
weatherCursor,
testWeatherValues);
}