Code example for SQLiteException

Methods: getMessage, printStackTrace

0
	public void onCreate(SQLiteDatabase db) {
		if (LOG_ON)Log.v("DBhelper.onCreate","Creating all the tables");
		try { 
			createTables(db);
		} catch(SQLiteException ex) {
			if (LOG_ON)Log.v("Create table exception", ex.getMessage());
		} 
	} 
	 
 
	@Override 
	/** 
	 * When upgrading database 
	 * All data will be lost 
	 *  
	 * @param db name of database to upgrade 
	 * @param oldVersion version number of existing database 
	 * @param newVersion version number of new database 
	 */ 
	public void onUpgrade(SQLiteDatabase db, int oldVersion,
		int newVersion) {
		Log.w("DB Upgrade", "Upgrading from version "+ oldVersion
			+" to "+ newVersion +", which will destroy all old data");
			dropAllTables(db);
			onCreate(db);
	} 
	 
	 
	@Override 
	/** 
	 * @param db database being opened 
	 */ 
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
	} 
	 
	 
	/** 
	 * Removes all tables & data from the database 
	 * **All data will be lost 
	 *  
	 * @param db name of database to clear 
	 */ 
	public void dropAllTables(SQLiteDatabase db){
		if (LOG_ON)Log.v("DBHelper.dropAllTables", "Dropping all tables");
	 
		try { 
			// drop order matters to avoid database constraint exception 
			db.execSQL("drop table if exists "+ Item_TagConst.TBL_NAME);
			db.execSQL("drop table if exists "+ ItemConst.TBL_NAME);
			db.execSQL("drop table if exists "+ CategoryConst.TBL_NAME);
			db.execSQL("drop table if exists "+ TagConst.TBL_NAME);
			 
		} catch (SQLiteException ex) {
			if (LOG_ON)Log.e("DBHelper.dropAllTables",ex.getMessage());
			ex.printStackTrace();
		} 
		if (LOG_ON)Log.v("DBhelper.dropAllTables", "Exiting in good status");
	} 
	 
	 
	/** 
	 * Create all tables required for WeShould application. Requires  
	 * that the tables do not currently exist in the database. 
	 * 
	 * @param db name of database to create tables in 
	 */ 
	public void createTables(SQLiteDatabase db){
		if (LOG_ON)Log.v("DBhelper.createTables","Creating tables");
		try { 
			// create order matters to avoid constraint exception		 
			db.execSQL(CREATE_TABLE_CATEGORY);
			db.execSQL(CREATE_TABLE_ITEM);
			db.execSQL(CREATE_TABLE_TAG);
			db.execSQL(CREATE_TABLE_ITEMTAG);
			 
		} catch(SQLiteException ex) {
			Log.e("DBHelper.createTables exception", ex.getMessage());
			ex.printStackTrace();
		} 
	} 
	 
	 
	/**