本文整理汇总了Java中android.database.SQLException类的典型用法代码示例。如果您正苦于以下问题:Java SQLException类的具体用法?Java SQLException怎么用?Java SQLException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SQLException类属于android.database包,在下文中一共展示了SQLException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insert
import android.database.SQLException; //导入依赖的package包/类
@Nullable
@Override
public Uri insert(Uri uri, ContentValues values) {
final SQLiteDatabase db = mCardsDBHelper.getWritableDatabase();
Uri returnUri = null;
int match = sUriMatcher.match(uri);
switch (match) {
case TRANSACTIONS: // Since insert and query all has same url
long transactionId = db.insert(DatabaseContract.TABLE_TRANSACTIONS, null, values);
if (transactionId > 0) {
returnUri = ContentUris.withAppendedId(DatabaseContract.CONTENT_URI, transactionId);
getContext().getContentResolver().notifyChange(uri, null);
} else {
throw new SQLException("Can't create ID");
}
break;
default:
throw new UnsupportedOperationException("This URI is not supported");
}
return returnUri;
}
示例2: query_forMessagesWithAccountAndRequiredFieldsWithNoOrderBy_throwsSQLiteException
import android.database.SQLException; //导入依赖的package包/类
@Test(expected = SQLException.class) //Handle this better?
public void query_forMessagesWithAccountAndRequiredFieldsWithNoOrderBy_throwsSQLiteException() {
Account account = Preferences.getPreferences(getContext()).newAccount();
account.getUuid();
Cursor cursor = getProvider().query(
Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages"),
new String[] {
EmailProvider.MessageColumns.ID,
EmailProvider.MessageColumns.FOLDER_ID,
EmailProvider.ThreadColumns.ROOT
},
"",
new String[] {},
"");
assertNotNull(cursor);
assertTrue(cursor.isAfterLast());
}
示例3: executeInsertThrowsAndDoesNotTrigger
import android.database.SQLException; //导入依赖的package包/类
@Test public void executeInsertThrowsAndDoesNotTrigger() {
SQLiteStatement statement = real.compileStatement("INSERT INTO " + TABLE_EMPLOYEE + " ("
+ NAME + ", " + USERNAME + ") "
+ "VALUES ('Alice Allison', 'alice')");
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES)
.skip(1) // Skip initial
.subscribe(o);
try {
db.executeInsert(TABLE_EMPLOYEE, statement);
fail();
} catch (SQLException ignored) {
}
o.assertNoMoreEvents();
}
示例4: testLegacyMigration
import android.database.SQLException; //导入依赖的package包/类
/**
* Should try to use the legacy parser by default, which is be unable to handle the SQL script.
*/
public void testLegacyMigration() {
try {
Configuration configuration = new Configuration.Builder(getContext())
.setDatabaseName("migration.db")
.setDatabaseVersion(2)
.create();
DatabaseHelper helper = new DatabaseHelper(configuration);
SQLiteDatabase db = helper.getWritableDatabase();
helper.onUpgrade(db, 1, 2);
fail("Should not be able to parse the SQL script.");
} catch (SQLException e) {
final String message = e.getMessage();
assertNotNull(message);
assertTrue(message.contains("syntax error"));
assertTrue(message.contains("near \"MockMigration\""));
}
}
示例5: Update
import android.database.SQLException; //导入依赖的package包/类
public boolean Update(@NonNull LucaMenu updateEntry) throws SQLException {
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_ROW_ID, updateEntry.GetId());
contentValues.put(KEY_WEEKDAY, updateEntry.GetWeekday().GetEnglishDay());
contentValues.put(KEY_DAY, String.valueOf(updateEntry.GetDate().DayOfMonth()));
contentValues.put(KEY_MONTH, String.valueOf(updateEntry.GetDate().Month()));
contentValues.put(KEY_YEAR, String.valueOf(updateEntry.GetDate().Year()));
contentValues.put(KEY_TITLE, updateEntry.GetTitle());
contentValues.put(KEY_DESCRIPTION, updateEntry.GetDescription());
contentValues.put(KEY_IS_ON_SERVER, String.valueOf(updateEntry.GetIsOnServer()));
contentValues.put(KEY_SERVER_ACTION, updateEntry.GetServerDbAction().toString());
_database.update(DATABASE_TABLE, contentValues, KEY_ROW_ID + "=" + updateEntry.GetId(), null);
return true;
}
示例6: getItm
import android.database.SQLException; //导入依赖的package包/类
public user getItm(int uid) throws SQLException {
Cursor cursor = this.db.query(true, DATABASE_MAINTABLE, this.yek_SH_flashkart, "uid == '" + uid + "' ", null, null, null, null, null);
user nam = new user();
if (cursor != null) {
cursor.moveToFirst();
nam.setId(cursor.getInt(cursor.getColumnIndex(KEY_ID)));
nam.setUid(cursor.getInt(cursor.getColumnIndex(KEY_UID)));
nam.setFname(cursor.getString(cursor.getColumnIndex(KEY_FNAME)));
nam.setLname(cursor.getString(cursor.getColumnIndex(KEY_LNAME)));
nam.setUsername(cursor.getString(cursor.getColumnIndex(KEY_USERNAME)));
nam.setPic(cursor.getString(cursor.getColumnIndex(KEY_PIC)));
nam.setStatus(cursor.getString(cursor.getColumnIndex(KEY_STATUS)));
nam.setPhone(cursor.getString(cursor.getColumnIndex(KEY_PHONE)));
nam.setUptime(cursor.getString(cursor.getColumnIndex(KEY_UPTIME)));
nam.setIsupdate(cursor.getInt(cursor.getColumnIndex(KEY_ISUPDATE)));
nam.setIsspecific(cursor.getInt(cursor.getColumnIndex(KEY_ISSPECEFIC)));
nam.setPicup(cursor.getInt(cursor.getColumnIndex(KEY_PICUP)));
nam.setStatusup(cursor.getInt(cursor.getColumnIndex(KEY_STATUSUP)));
nam.setPhoneup(cursor.getInt(cursor.getColumnIndex(KEY_PHONEUP)));
nam.setIsonetime(cursor.getInt(cursor.getColumnIndex(KEY_ISONETIME)));
}
assert cursor != null;
cursor.close();
return nam;
}
示例7: insert
import android.database.SQLException; //导入依赖的package包/类
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
SQLiteDatabase db = sqlHelper.getReadableDatabase();
int uriRequest = uriMatcher.match(uri);
Uri insertUri;
long insertid;
if (uriRequest == ContentContract.TASK){
insertid = db.insert(ContentContract.TABLE, null, contentValues);
if (insertid > 0){
insertUri = ContentUris.withAppendedId(ContentContract.CONTENT_URI, insertid);
} else {
throw new SQLException("Failed to insert row into " + uri.getPath());
}
} else {
throw new UnsupportedOperationException("unknown uri");
}
getContext().getContentResolver().notifyChange(uri, null);
return insertUri;
}
示例8: getItm
import android.database.SQLException; //导入依赖的package包/类
public hideObjc getItm(int ID) throws SQLException {
Cursor cursor = this.db.query(true, DATABASE_MAINTABLE, this.yek_SH_flashkart, "dialog_id == '" + ID + "' AND isHidden = 1", null, null, null, null, null);
hideObjc nam = new hideObjc();
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
nam.setId(cursor.getInt(cursor.getColumnIndex(KEY_ID)));
nam.setDialog_id(cursor.getInt(cursor.getColumnIndex(KEY_DIALOG_ID)));
nam.setHideCode(cursor.getInt(cursor.getColumnIndex(KEY_HIDE_CODE)));
nam.setIsChannel(cursor.getInt(cursor.getColumnIndex(KEY_IS_CHANNEL)));
nam.setIsGroup(cursor.getInt(cursor.getColumnIndex(KEY_IS_GROUP)));
nam.setIsHidden(cursor.getInt(cursor.getColumnIndex(KEY_IS_HIDDEN)));
}
assert cursor != null;
cursor.close();
return nam;
}
示例9: beginTransaction
import android.database.SQLException; //导入依赖的package包/类
private void beginTransaction(SQLiteTransactionListener transactionListener, boolean exclusive) {
acquireReference();
try {
// getThreadSession().beginTransaction(
// exclusive ? ShadowSQLiteSession.TRANSACTION_MODE_EXCLUSIVE :
// ShadowSQLiteSession.TRANSACTION_MODE_IMMEDIATE,
// transactionListener,
// getThreadDefaultConnectionFlags(false /*readOnly*/), null);
isTransaction = true;
mConnection.setAutoCommit(false);
} catch (java.sql.SQLException e) {
e.printStackTrace();
} finally {
releaseReference();
}
}
示例10: insert
import android.database.SQLException; //导入依赖的package包/类
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
int match = sUriMatcher.match(uri);
Uri returnUri;
switch (match) {
case RECIPES:
Recipe recipe = buildRecipeFromContentValues(contentValues);
long recipeId = recipeDao.insertRecipe(recipe);
if (recipeId > 0){
returnUri = ContentUris.withAppendedId(RecipesContract.RecipeEntry.CONTENT_URI, recipeId);
} else {
throw new SQLException("Failed to insert row into " + uri);
}
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
mContext.getContentResolver().notifyChange(uri, null);
return returnUri;
}
示例11: onClick
import android.database.SQLException; //导入依赖的package包/类
@Override
public void onClick(View view) {
try {
// update this group to database ....
ArticlesDataSource mDbHelper = new ArticlesDataSource(getApplicationContext());
mDbHelper.createDatabase();
mDbHelper.open();
long updatedId = mDbHelper.updateGroup(groupName, listOfIdsLessons, getIdGroupToBeUpdated());
if (updatedId != -1) {
//Toast.makeText(getApplicationContext(), R.string.group_has_been_saved, Toast.LENGTH_SHORT).show();
// ... and go to activity to show it
Intent intent = new Intent(getApplicationContext(), AllArticlesListViewActivity.class);
intent.putExtra("group_id", getIdGroupToBeUpdated());
intent.putExtra("group_name", groupName);
intent.putExtra("status_what_show", ActivityArticlesStatusToShow.SHOW_ALL_GROUPS);
startActivity(intent);
} else {
// throw exception
}
} catch (SQLException e) {
e.printStackTrace();
}
}
示例12: findArticles
import android.database.SQLException; //导入依赖的package包/类
/**
* We have to options to find articles:
* 1. Find all articles - in this case we have ids as null
* 2. Find articles inside group - in this case we must to pass ids of group. In activity we have getIdsOfGroup() to do this.
*
* @param articleName name of article
* @param ids sequence of ids of article where we need to search
* @return Cursor
*/
public Cursor findArticles(String articleName, String ids) {
try {
String sql;
if (ids == null) {
sql = "select _id as _id, unit_number as title, html as html from articles \n" +
"where unit_number like '%" + articleName + "%' order by _id ";
} else {
sql = "select _id as _id, unit_number as title, html as html from articles \n" +
"where unit_number like '%" + articleName + "%' and _id in (" + ids + ") order by _id ";
}
Cursor mCur = mDb.rawQuery(sql, null);
if (mCur != null) {
mCur.moveToNext();
}
return mCur;
} catch (SQLException mSQLException) {
throw mSQLException;
}
}
示例13: Update
import android.database.SQLException; //导入依赖的package包/类
public boolean Update(@NonNull ShoppingEntry updateEntry) throws SQLException {
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_ROW_ID, updateEntry.GetId());
contentValues.put(KEY_NAME, updateEntry.GetName());
contentValues.put(KEY_GROUP, updateEntry.GetGroup().toString());
contentValues.put(KEY_QUANTITY, updateEntry.GetQuantity());
contentValues.put(KEY_UNIT, updateEntry.GetUnit());
contentValues.put(KEY_BOUGHT, (updateEntry.GetBought() ? "1" : "0"));
contentValues.put(KEY_IS_ON_SERVER, String.valueOf(updateEntry.GetIsOnServer()));
contentValues.put(KEY_SERVER_ACTION, updateEntry.GetServerDbAction().toString());
_database.update(DATABASE_TABLE, contentValues, KEY_ROW_ID + "=" + updateEntry.GetId(), null);
return true;
}
示例14: onCreate
import android.database.SQLException; //导入依赖的package包/类
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
try {
String sql = "CREATE TABLE " + TABLE_NAME
+ "(" + COLUMN_ID +
" INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COLUMN_LEVEL +
" INTEGER, " +
COLUMN_CONTENT +
" VARCHAR, " +
COLUMN_DATE +
" INTEGER);";
sqLiteDatabase.execSQL(sql);
} catch (SQLException ex) {
Log.d("PTSqliteHelper", ex.getMessage());
return;
}
}
示例15: upgradeDbTo310
import android.database.SQLException; //导入依赖的package包/类
private void upgradeDbTo310(SQLiteDatabase db, int oldVersion) throws SQLException {
String updSql;
if (!columnExists(db, TABLE_NAME_REFUEL, COL_NAME_REFUEL__AMOUNT)) {
updSql = "ALTER TABLE " + TABLE_NAME_REFUEL + " ADD " + COL_NAME_REFUEL__AMOUNT + " NUMERIC NULL ";
db.execSQL(updSql);
updSql = "UPDATE " + TABLE_NAME_REFUEL + " SET " + COL_NAME_REFUEL__AMOUNT + " = " + COL_NAME_REFUEL__QUANTITYENTERED + " * "
+ COL_NAME_REFUEL__PRICE;
db.execSQL(updSql);
}
if (!columnExists(db, TABLE_NAME_REFUEL, COL_NAME_REFUEL__AMOUNTENTERED)) {
updSql = "ALTER TABLE " + TABLE_NAME_REFUEL + " ADD " + COL_NAME_REFUEL__AMOUNTENTERED + " NUMERIC NULL ";
db.execSQL(updSql);
updSql = "UPDATE " + TABLE_NAME_REFUEL + " SET " + COL_NAME_REFUEL__AMOUNTENTERED + " = " + COL_NAME_REFUEL__QUANTITYENTERED + " * "
+ COL_NAME_REFUEL__PRICEENTERED;
db.execSQL(updSql);
}
upgradeDbTo330(db, oldVersion);
}