本文整理了Java中android.database.SQLException
类的一些代码示例,展示了SQLException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLException
类的具体详情如下:
包路径:android.database.SQLException
类名称:SQLException
暂无
代码示例来源:origin: google/agera
@Override
public void onCreate(final SQLiteDatabase sqLiteDatabase) {
throw new SQLException();
}
代码示例来源:origin: filippella/Dagger-Rx-Database-MVP
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(CREATE_TABLE);
} catch(SQLException e) {
Log.d(TAG, e.getMessage());
}
}
代码示例来源:origin: com.github.japgolly.android.test/robolectric
@Implementation
public void execSQL(String sql) throws android.database.SQLException {
if (!isOpen()) {
throw new IllegalStateException("database not open");
}
try {
String scrubbedSql= DatabaseConfig.getScrubSQL(sql);
connection.createStatement().execute(scrubbedSql);
} catch (java.sql.SQLException e) {
android.database.SQLException ase = new android.database.SQLException();
ase.initCause(e);
throw ase;
}
}
代码示例来源:origin: sendtion/XRichText
db.setTransactionSuccessful();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
代码示例来源:origin: matt-allen/repay-android
/**
* Replace friend data in database with that passed in here
* @param friend
*/
public void updateFriendRecord(Friend friend) throws SQLException, NullPointerException{
ContentValues values = new ContentValues();
values.put(Names.F_REPAYID, friend.getRepayID());
if(friend.getLookupURI()!=null){
values.put(Names.F_LOOKUPURI, friend.getLookupURI());
}
else{
values.putNull(Names.F_LOOKUPURI);
}
values.put(Names.F_NAME, friend.getName());
values.put(Names.F_DEBT, friend.getDebt().toString());
SQLiteDatabase db = this.getWritableDatabase();
try {
db.update(Names.F_TABLENAME, values, Names.F_REPAYID+"=?",
new String[]{friend.getRepayID()});
} catch (SQLException e) {
Log.e(TAG, e.getMessage());
e.printStackTrace();
throw e;
} finally {
db.close();
}
}
代码示例来源:origin: posm/OpenMapKitAndroid
@Override
public void onCreate(SQLiteDatabase db) {
Log.i(TAG, "onCreate() called... Setting up application's database.");
// Create The table(s)
String metadata = "CREATE TABLE " + TABLE_METADATA + " (" + FIELD_METADATA_NAME + " TEXT UNIQUE, " + FIELD_METADATA_VALUE + " TEXT);";
String resources = "CREATE TABLE " + TABLE_RESOURCES + " (" + FIELD_RESOURCES_URL + " TEXT UNIQUE, " + FIELD_RESOURCES_DATA + " BLOB, " + FIELD_RESOURCES_STATUS + " TEXT);";
db.beginTransaction();
try {
db.execSQL(metadata);
db.execSQL(resources);
db.setTransactionSuccessful();
} catch (SQLException e) {
Log.e(TAG, "Error creating database: " + e.toString());
e.printStackTrace();
} finally {
db.endTransaction();
}
}
代码示例来源:origin: lordi/tickmate
Log.d("tickmate", "Ignoring SQL error: " + e.toString());
代码示例来源:origin: pires/android-obd-reader
/**
* DESCRIPTION:
* Deletes a specified trip record from the log.
*
* @param id - the TripRecord to delete.
* @return boolean flag indicating success/failure (true=success)
*/
public boolean deleteTrip(long id) {
final String tag = TAG + ".deleteRecord()";
boolean success = false;
try {
String whereClause = RECORD_ID + "=" + id;
String[] whereArgs = null;
int count = db.delete(RECORDS_TABLE, whereClause, whereArgs);
success = (count == 1);
} catch (SQLException e) {
Log.e(tag, "SQLException: " + e.getMessage());
}
return success;
}
代码示例来源:origin: techyourchance/idocare-android
@Override
public void onCreate(SQLiteDatabase db) {
Log.v(TAG, "onCreate is called");
try {
db.execSQL(CREATE_REQUESTS_TABLE);
db.execSQL(CREATE_USERS_TABLE);
db.execSQL(CREATE_USER_ACTIONS_TABLE);
db.execSQL(CREATE_TEMP_ID_MAPPINGS_TABLE);
} catch (SQLException e) {
e.printStackTrace();
}
}
代码示例来源:origin: crazyhitty/Munch
public DatabaseAdapter open() throws SQLException {
try {
mDatabaseHelper.openDataBase();
mDatabaseHelper.close();
mDatabase = mDatabaseHelper.getReadableDatabase();
} catch (SQLException mSQLException) {
Log.e("OpenDb", "open >>" + mSQLException.toString());
throw mSQLException;
}
return this;
}
代码示例来源:origin: ankidroid/Anki-Android
public String queryString(String query) throws SQLException {
Cursor cursor = null;
try {
cursor = mDatabase.query(query, null);
if (!cursor.moveToNext()) {
throw new SQLException("No result for query: " + query);
}
return cursor.getString(0);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
代码示例来源:origin: fookwood/Launcher3
private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
db.beginTransaction();
try {
db.execSQL("ALTER TABLE favorites ADD COLUMN "
+ columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
db.setTransactionSuccessful();
} catch (SQLException ex) {
Log.e(TAG, ex.getMessage(), ex);
return false;
} finally {
db.endTransaction();
}
return true;
}
代码示例来源:origin: enricocid/LaunchEnr
private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
db.beginTransaction();
try {
db.execSQL("ALTER TABLE favorites ADD COLUMN "
+ columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
db.setTransactionSuccessful();
} catch (SQLException ex) {
ex.printStackTrace();
return false;
} finally {
db.endTransaction();
}
return true;
}
代码示例来源:origin: dimtion/Shaarlier
@Override
protected void onResume() {
super.onResume();
final ListView accountsListView = (ListView) findViewById(R.id.accountListView);
AccountsSource accountsSource = new AccountsSource(getApplicationContext());
try {
accountsSource.rOpen();
List<ShaarliAccount> accountsList = accountsSource.getAllAccounts();
ArrayAdapter<ShaarliAccount> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, accountsList);
accountsListView.setAdapter(adapter);
if (accountsList.isEmpty())
findViewById(R.id.noAccountToShow).setVisibility(View.VISIBLE);
else
findViewById(R.id.noAccountToShow).setVisibility(View.GONE);
} catch (SQLException e) {
Log.e("DB_ERROR", e.toString());
} finally {
accountsSource.close();
}
accountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
ShaarliAccount clickedAccount = (ShaarliAccount) accountsListView.getItemAtPosition(position);
addOrEditAccount(clickedAccount);
}
});
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public Uri insert(Uri url, ContentValues initialValues) {
long rowID=
db.getWritableDatabase().insert(TABLE, Constants.TITLE,
initialValues);
if (rowID > 0) {
Uri uri=
ContentUris.withAppendedId(Provider.Constants.CONTENT_URI,
rowID);
getContext().getContentResolver().notifyChange(uri, null);
return(uri);
}
throw new SQLException("Failed to insert row into " + url);
}
代码示例来源:origin: klinker24/launcher3
private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
db.beginTransaction();
try {
db.execSQL("ALTER TABLE favorites ADD COLUMN "
+ columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
db.setTransactionSuccessful();
} catch (SQLException ex) {
Log.e(TAG, ex.getMessage(), ex);
return false;
} finally {
db.endTransaction();
}
return true;
}
代码示例来源:origin: zhangliangming/HappyPlayer-AS
/**
* 删除sid的相关数据
*/
public void delete(String sid) {
db = mDBHlper.getWritableDatabase();
try {
db.delete(TBL_NAME, "sid=?", new String[]{sid});
} catch (SQLException e) {
e.printStackTrace();
}
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public Uri insert(Uri url, ContentValues initialValues) {
long rowID=
db.getWritableDatabase().insert(TABLE, Constants.TITLE,
initialValues);
if (rowID > 0) {
Uri uri=
ContentUris.withAppendedId(Provider.Constants.CONTENT_URI,
rowID);
getContext().getContentResolver().notifyChange(uri, null);
return(uri);
}
throw new SQLException("Failed to insert row into " + url);
}
代码示例来源:origin: klinker24/Android-Blur-Launcher
private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
db.beginTransaction();
try {
db.execSQL("ALTER TABLE favorites ADD COLUMN "
+ columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
db.setTransactionSuccessful();
} catch (SQLException ex) {
Log.e(TAG, ex.getMessage(), ex);
return false;
} finally {
db.endTransaction();
}
return true;
}
代码示例来源:origin: zhangliangming/HappyPlayer-AS
/**
* 删除所有的数据
*/
public void delete() {
db = mDBHlper.getWritableDatabase();
try {
db.execSQL("drop table if exists " + TBL_NAME);
db.execSQL(CREATE_TBL);
} catch (SQLException e) {
e.printStackTrace();
}
}
内容来源于网络,如有侵权,请联系作者删除!