@Override public void onCreate(final SQLiteDatabase sqLiteDatabase) { throw new SQLException(); }
@Override public void onCreate(SQLiteDatabase db) { try { db.execSQL(CREATE_TABLE); } catch(SQLException e) { Log.d(TAG, e.getMessage()); } }
@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; } }
db.setTransactionSuccessful(); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace();
/** * 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(); } }
@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(); } }
Log.d("tickmate", "Ignoring SQL error: " + e.toString());
/** * 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; }
@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(); } }
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; }
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(); } } }
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; }
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; }
@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); } }); }
@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); }
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; }
/** * 删除sid的相关数据 */ public void delete(String sid) { db = mDBHlper.getWritableDatabase(); try { db.delete(TBL_NAME, "sid=?", new String[]{sid}); } catch (SQLException e) { e.printStackTrace(); } }
@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); }
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; }
/** * 删除所有的数据 */ public void delete() { db = mDBHlper.getWritableDatabase(); try { db.execSQL("drop table if exists " + TBL_NAME); db.execSQL(CREATE_TBL); } catch (SQLException e) { e.printStackTrace(); } }