Example usage for android.database SQLException printStackTrace

List of usage examples for android.database SQLException printStackTrace

Introduction

In this page you can find the example usage for android.database SQLException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.most.persistence.DBAdapter.java

/**
 * Flushes all currently buffered data to the database. This method
 * <em>does not</em> require to acquire the DB lock beforehand.
 *///from w  ww  . j  av a 2 s . com
public void flushData() {
    Log.d(TAG, "Flushing MoST db.");
    logger.info("Flushing MoST db.");
    _runningDump.set(true);
    long start = System.currentTimeMillis();
    if (open() == null) {
        Log.e(TAG, "Unable to write data to db.");
        logger.error("Unable to write data to db.");
        _runningDump.set(false);
        return;
    }
    updateList();
    int linesCount = 0;
    _db.beginTransaction();
    try {
        LinkedBlockingQueue<ContentValues> list;
        while ((list = _dataToDump.poll()) != null) {
            for (ContentValues data : list) {
                String tableName = data.getAsString(FLD_TABLE);
                data.remove(FLD_TABLE);
                _db.insert(tableName, null, data);
                linesCount++;
            }
        }
        // commit on successful write
        _db.setTransactionSuccessful();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        _db.endTransaction();
        close();
        start = System.currentTimeMillis() - start;
        Log.i(TAG, "DB write time: " + start + "ms for " + linesCount + " entries.");
        _runningDump.set(false);
    }
}

From source file:com.repay.android.adddebt.AddDebtActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // If the available screen size is that of an average tablet (as defined
    // in the Android documentation) then allow the screen to rotate
    if (getResources().getBoolean(R.bool.lock_orientation)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }/*from  w  ww . ja  v a 2 s. c o m*/
    mActionBar = getActionBar();
    mActionBar.setDisplayHomeAsUpEnabled(true);
    mActionBar.setDisplayShowTitleEnabled(true);
    mActionBar.setSubtitle(R.string.fragment_choosefriend_subtitle);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_adddebt);
    mSelectedFriends = new ArrayList<Friend>();
    mDB = new DatabaseHandler(this);

    // Instantiate Fragments
    mChoosePerson = new ChoosePersonFragment();
    mEnterAmount = new EnterAmountFragment();
    mSummary = new DebtSummaryFragment();
    mFrameLayoutRes = R.id.activity_adddebt_framelayout;

    if (getIntent().getExtras() != null) {
        Bundle bundle = getIntent().getExtras();
        if (bundle.containsKey(NO_OF_FRIENDS_SELECTED)) {
            try {
                int count = bundle.getInt(NO_OF_FRIENDS_SELECTED);
                mSelectedFriends = new ArrayList<Friend>();
                for (int i = 1; i <= count; i++) {
                    mSelectedFriends
                            .add(mDB.getFriendByRepayID(bundle.getString(REPAY_ID + Integer.toString(i))));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        Log.i(TAG, "Friend data from FriendDetailsActivity, not selected from the list");
    } else if (savedInstanceState != null && savedInstanceState.containsKey(NO_OF_FRIENDS_SELECTED)) {
        int count = savedInstanceState.getInt(NO_OF_FRIENDS_SELECTED);
        mSelectedFriends = new ArrayList<Friend>();
        for (int i = 1; i <= count; i++) {
            mSelectedFriends
                    .add(mDB.getFriendByRepayID(savedInstanceState.getString(REPAY_ID + Integer.toString(i))));
        }
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(AddDebtActivity.AMOUNT)) {
        mAmount = new BigDecimal(savedInstanceState.getString(AddDebtActivity.AMOUNT));
    }
    // Show the first fragment
    mFragMan = getSupportFragmentManager().beginTransaction();
    mFragMan.add(mFrameLayoutRes, mChoosePerson);
    mFragMan.commit();
}

From source file:de.nware.app.hsDroid.provider.onlineService2Provider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    Cursor cursor = null;/*from  w ww  .  j a va2 s .  co m*/
    switch (mUriMatcher.match(uri)) {
    case EXAMS:
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
        qb.setTables(mOpenHelper.getTableName());
        qb.setProjectionMap(examsProjectionMap);
        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        try {
            cursor = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
        } catch (SQLException e) {
            e.printStackTrace();
            Log.d(TAG, "SqlError: " + e.getMessage());
        }
        cursor.setNotificationUri(getContext().getContentResolver(), uri);
        break;
    case EXAMS_UPDATE:
        MatrixCursor cur = new MatrixCursor(EXAMS_UPDATE_COLUMNS);
        Integer[] columnValues = updateGrades();
        cur.addRow(new Object[] { 0, columnValues[0], columnValues[1] });
        return cur;
    case EXAMINFOS:
        cursor = getExamInfos(selectionArgs[0], selectionArgs[1], false);
        break;
    case CERTIFICATIONS:
        cursor = getCertifications();
        break;
    default:
        throw new IllegalArgumentException("Unbekannte URI " + uri);
    }

    return cursor;
}

From source file:com.mobile.system.db.abatis.AbatisService.java

public int execute(String sqlId, Map<String, Object> bindParams) {
    getDbObject();//  www.  j  a v  a  2  s  . c om
    int row = 0;
    int pointer = context.getResources().getIdentifier(sqlId, "string", context.getPackageName());
    if (pointer == 0) {
        Log.e(TAG, "undefined sql id : " + sqlId);
        return row;
    }
    String sql = context.getResources().getString(pointer);

    if (bindParams != null) {
        Iterator<String> mapIterator = bindParams.keySet().iterator();
        while (mapIterator.hasNext()) {
            String key = mapIterator.next();
            Object value = bindParams.get(key);
            if (value != null) {
                sql = getFinalSql(sql, key.toLowerCase(), value.toString());
            } else {
                sql = getFinalSql(sql, key.toLowerCase(), " ");
            }

        }
    }
    if (sql.indexOf('#') != -1) {
        Log.e(TAG, "undefined parameter sql : " + sql);
        return row;
    }
    try {
        System.out.println(sql);
        dbObj.execSQL(sql);
        Log.d(TAG, "Run sql : " + sql);
        dbObj.close();
        row += 1;
    } catch (SQLException e) {
        System.out.println("Error sql : " + sql);
        return row;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return row;
}