android.database.SQLException.printStackTrace()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中android.database.SQLException.printStackTrace()方法的一些代码示例,展示了SQLException.printStackTrace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLException.printStackTrace()方法的具体详情如下:
包路径:android.database.SQLException
类名称:SQLException
方法名:printStackTrace

SQLException.printStackTrace介绍

暂无

代码示例

代码示例来源:origin: sendtion/XRichText

db.setTransactionSuccessful();
} catch (SQLException e) {
  e.printStackTrace();
} catch (Exception e) {
  e.printStackTrace();

代码示例来源: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: 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: 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: 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();
  }
}

代码示例来源:origin: techyourchance/idocare-android

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  Log.v(TAG, "onUpgrade is called. Old ver: " + oldVersion + " new ver: " + newVersion);
  try {
    db.execSQL("DROP TABLE IF EXISTS " + REQUESTS_TABLE_NAME);
    db.execSQL("DROP TABLE IF EXISTS " + USERS_TABLE_NAME);
    db.execSQL("DROP TABLE IF EXISTS " + USER_ACTIONS_TABLE_NAME);
    db.execSQL("DROP TABLE IF EXISTS " + TEMP_ID_MAPPINGS_TABLE_NAME);
    onCreate(db);
  } catch (SQLException e) {
    e.printStackTrace();
  }
}

代码示例来源: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: lfkdsk/JustWeEngine

public boolean open(Context context) {
  try {
    mDBHelper = new DataBaseHelper(context, mDBMessage.SQL_NAME, 1);
    mDB = mDBHelper.getWritableDatabase();
  } catch (SQLException e) {
    e.printStackTrace();
    return false;
  }
  return true;
}

代码示例来源:origin: MindorksOpenSource/android-dagger2-example

private void tableCreateStatements(SQLiteDatabase db) {
  try {
    db.execSQL(
        "CREATE TABLE IF NOT EXISTS "
            + USER_TABLE_NAME + "("
            + USER_COLUMN_USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + USER_COLUMN_USER_NAME + " VARCHAR(20), "
            + USER_COLUMN_USER_ADDRESS + " VARCHAR(50), "
            + USER_COLUMN_USER_CREATED_AT + " VARCHAR(10) DEFAULT " + getCurrentTimeStamp() + ", "
            + USER_COLUMN_USER_UPDATED_AT + " VARCHAR(10) DEFAULT " + getCurrentTimeStamp() + ")"
    );
  } catch (SQLException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: enricocid/LaunchEnr

@Thunk boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) {
  db.beginTransaction();
  try {
    if (addRankColumn) {
      // Insert new column for holding rank
      db.execSQL("ALTER TABLE favorites ADD COLUMN rank INTEGER NOT NULL DEFAULT 0;");
    }
    // Get a map for folder ID to folder width
    Cursor c = db.rawQuery("SELECT container, MAX(cellX) FROM favorites"
        + " WHERE container IN (SELECT _id FROM favorites WHERE itemType = ?)"
        + " GROUP BY container;",
        new String[] {Integer.toString(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)});
    while (c.moveToNext()) {
      db.execSQL("UPDATE favorites SET rank=cellX+(cellY*?) WHERE "
          + "container=? AND cellX IS NOT NULL AND cellY IS NOT NULL;",
          new Object[] {c.getLong(1) + 1, c.getLong(0)});
    }
    c.close();
    db.setTransactionSuccessful();
  } catch (SQLException ex) {
    // Old version remains, which means we wipe old data
    ex.printStackTrace();
    return false;
  } finally {
    db.endTransaction();
  }
  return true;
}

代码示例来源:origin: Jhuster/JNote

public boolean open(Context context) {
  try {
    mDBHelper = new DatabaseHelper(context, DB_NAME, DB_VERSION);
    mDB = mDBHelper.getWritableDatabase();
  } catch (SQLException e) {
    e.printStackTrace();
    return false;
  }
  return true;
}

代码示例来源:origin: JackWHLiu/jackknife

/* package */ <T extends OrmTable> void _createTable(Class<T> tableClass, SQLiteDatabase db) {
  String tableName = getTableName(tableClass);
  Field[] fields = tableClass.getDeclaredFields();
  StringBuilder sqlBuilder = new StringBuilder(CREATE_TABLE + SPACE + IF_NOT_EXISTS + SPACE
      + tableName + LEFT_PARENTHESIS);//table header
  boolean hasPrimaryKey = false;
  for (Field field : fields) {
    field.setAccessible(true);
    Ignore ignore = field.getAnnotation(Ignore.class);
    if (ignore != null) {
      continue;
    }
    ColumnBuilder fieldBuilder = createColumnBuilder(field);
    if (fieldBuilder.isPrimaryKey) {
      hasPrimaryKey = true;
    }
    sqlBuilder.append(fieldBuilder.build()).append(COMMA);
  }
  if (!hasPrimaryKey) {
    throw new ConstraintException("Lack valid primary key.");
  }
  try {
    String sql = sqlBuilder.deleteCharAt(sqlBuilder.length() - 1).append(RIGHT_PARENTHESIS)
        .append(SEMICOLON).toString();
    OrmLog.d(sql);
    db.execSQL(sql);
  } catch (SQLException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: enricocid/LaunchEnr

ex.printStackTrace();
  folderIds.clear();
} finally {

代码示例来源:origin: enricocid/LaunchEnr

ex.printStackTrace();

代码示例来源:origin: matt-allen/repay-android

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (data != null && requestCode == PICK_CONTACT_REQUEST) {
    try {
      String contactUri = data.getData().toString();
      String displayName = ContactsContractHelper.getNameForContact(this, contactUri);
      Friend pickerResult = new Friend(mFriend.getRepayID(), contactUri, displayName, mFriend.getDebt());
      mDB.updateFriendRecord(pickerResult);
    } catch (IndexOutOfBoundsException e) {
      e.printStackTrace();
      Toast.makeText(this, "Problem in getting result from your contacts", Toast.LENGTH_SHORT).show();
    } catch (SQLException e) {
      e.printStackTrace();
      Toast.makeText(this, "Unable to add this person to the database", Toast.LENGTH_SHORT).show();
    }
  }
}

代码示例来源:origin: JackWHLiu/jackknife

/* package */ <T extends OrmTable> void _upgradeTable(Class<T> tableClass, SQLiteDatabase db) {
  String tableName = getTableName(tableClass);
  Field[] fields = tableClass.getDeclaredFields();
  for (Field field : fields) {
    field.setAccessible(true);
    Ignore ignore = field.getAnnotation(Ignore.class);
    if (ignore != null) {
      continue;
    }
    String columnName = getColumnName(field);
    try {
      String sql = ALTER_TABLE + SPACE + tableName + SPACE + IF_NOT_EXISTS + SPACE
          + columnName + SPACE + ADD_COLUMN + SPACE
          + createColumnBuilder(field).build() + SEMICOLON;
      OrmLog.d(sql);
      db.execSQL(sql);
    } catch (SQLException 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: enricocid/LaunchEnr

e.printStackTrace();
} finally {
  if (cursor != null) {

代码示例来源:origin: matt-allen/repay-android

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
  super.onActivityResult(requestCode, resultCode, data);
  if (data != null && resultCode == Activity.RESULT_OK && requestCode == PICK_CONTACT_REQUEST)
  {
    try
    {
      String contactUri = data.getData().toString();
      String displayName = ContactsContractHelper.getNameForContact(getActivity(), contactUri);
      Friend pickerResult = new Friend(DatabaseHandler.generateRepayID(), contactUri, displayName, new BigDecimal("0"));
      ((DebtActivity)getActivity()).getDBHandler().addFriend(pickerResult);
      new GetFriendsFromDB().execute();
    }
    catch (IndexOutOfBoundsException e)
    {
      e.printStackTrace();
      Toast.makeText(getActivity(), R.string.problem_getting_from_contacts, Toast.LENGTH_LONG).show();
    }
    catch (SQLException e)
    {
      e.printStackTrace();
      Toast.makeText(getActivity(), R.string.problem_adding_to_repay, Toast.LENGTH_LONG).show();
    }
  }
}

代码示例来源:origin: zhangliangming/HappyPlayer-AS

/**
 * 插入ContentValues
 */
private void insert(ContentValues values, SongInfo songInfo) {
  db = mDBHlper.getWritableDatabase();
  try {
    db.insert(TBL_NAME, null, values);
    if (songInfo.getDownloadStatus() == SongInfo.DOWNLOADED) {
      SongMessage songMessage = new SongMessage();
      songMessage.setSongInfo(songInfo);
      songMessage.setType(SongMessage.ADDMUSIC);
      // 通知
      ObserverManage.getObserver().setMessage(songMessage);
    }
  } catch (SQLException e) {
    e.printStackTrace();
  }
}

相关文章