當前位置: 首頁>>代碼示例>>Java>>正文


Java SQLException類代碼示例

本文整理匯總了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;
}
 
開發者ID:talCrafts,項目名稱:Udhari,代碼行數:23,代碼來源:TxProvider.java

示例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());
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:20,代碼來源:EmailProviderTest.java

示例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();
}
 
開發者ID:jiechic,項目名稱:sqlbrite-sqlcipher,代碼行數:17,代碼來源:BriteDatabaseTest.java

示例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\""));
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:ParserConfigurationTest.java

示例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;
}
 
開發者ID:GuepardoApps,項目名稱:LucaHome-AndroidApplication,代碼行數:18,代碼來源:DatabaseMenuList.java

示例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;
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:27,代碼來源:userDBAdapter.java

示例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;
}
 
開發者ID:marckregio,項目名稱:maklib,代碼行數:23,代碼來源:ContentHandler.java

示例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;
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:18,代碼來源:hideDBAdapter.java

示例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();
    }
}
 
開發者ID:kkmike999,項目名稱:YuiHatano,代碼行數:17,代碼來源:ShadowSQLiteDatabase.java

示例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;
}
 
開發者ID:harrynp,項目名稱:BakingApp,代碼行數:22,代碼來源:RecipesProvider.java

示例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();
    }
}
 
開發者ID:white-collar,項目名稱:mobile-grammar,代碼行數:24,代碼來源:AddReminderToGroupActivity.java

示例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;
    }
}
 
開發者ID:white-collar,項目名稱:mobile-grammar,代碼行數:31,代碼來源:ArticlesDataSource.java

示例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;
}
 
開發者ID:GuepardoApps,項目名稱:LucaHome-AndroidApplication,代碼行數:17,代碼來源:DatabaseShoppingList.java

示例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;
    }
}
 
開發者ID:Jusenr,項目名稱:androidtools,代碼行數:19,代碼來源:PTSqliteHelper.java

示例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);
}
 
開發者ID:mkeresztes,項目名稱:AndiCar,代碼行數:20,代碼來源:DB.java


注:本文中的android.database.SQLException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。