src/com/shrewdify/diaroser/utils/DbHelper.java
public  int readUserBalance(String username) throws SQLException{
		int balance = Constants.MINUSONE;
		int reservedUnits = Constants.ZERO;
		int reservedBuff = 5000;
		if (connection != null) {
			psgetBalance.setString(1, username);
			boolean userexist = Constants.FL_VAL;
			ResultSet resultSet = psgetBalance.executeQuery();
			while (resultSet.next()) { // retrieve data
				balance =  resultSet.getInt(3);
				reservedUnits = resultSet.getInt(4);
				userexist = true;
			}

			if ((reservedUnits + reservedBuff) <= balance) {
				reservedUnits = reservedUnits + reservedBuff;
				psUpdBalance.setInt(1,  reservedUnits);
				psUpdBalance.setString(2, username);
				int rowsUpdates = psUpdBalance.executeUpdate();

				if (rowsUpdates == Constants.ONE)
					balance = reservedBuff;
			} else if (userexist) {
				balance = Constants.ZERO;
			} else {

				balance = Constants.MINUSONE;
			}
			resultSet.close();
		}
		return balance;

	}
/**
	 * 
	 * @param username  //Account no of the user. 
	 * @return  //Returns balance allocated to User.
	 * 
	 * @throws SQLException
	 * 
	 * It reads the user balance based on his name and allocates the buffer amount to the user.
	 */
@param username  //Account no of the user.
@return  //Returns balance allocated to User.



It reads the user balance based on his name and allocates the buffer amount to the user.
@param username // Account no of the user . @return // Returns balance allocated to User . It reads the user balance based on his name and allocates the buffer amount to the user .
public  int readUserBalance(String username) throws SQLException{
		int balance = Constants.MINUSONE;
		int reservedUnits = Constants.ZERO;
		int reservedBuff = 5000;
		if (connection != null) {
			psgetBalance.setString(1, username);
			boolean userexist = Constants.FL_VAL;
			ResultSet resultSet = psgetBalance.executeQuery();
			while (resultSet.next()) { 
				balance =  resultSet.getInt(3);
				reservedUnits = resultSet.getInt(4);
				userexist = true;
			}
			if ((reservedUnits + reservedBuff) <= balance) {
				reservedUnits = reservedUnits + reservedBuff;
				psUpdBalance.setInt(1,  reservedUnits);
				psUpdBalance.setString(2, username);
				int rowsUpdates = psUpdBalance.executeUpdate();
				if (rowsUpdates == Constants.ONE)
					balance = reservedBuff;
			} else if (userexist) {
				balance = Constants.ZERO;
			} else {
				balance = Constants.MINUSONE;
			}
			resultSet.close();
		}
		return balance;
	}
public int readUserBalance ( String username ) throws SQLException { int balance = Constants . MINUSONE ; int reservedUnits = Constants . ZERO ; int reservedBuff = 5000 ; if ( connection != null ) { psgetBalance . setString ( 1 , username ) ; boolean userexist = Constants . FL_VAL ; ResultSet resultSet = psgetBalance . executeQuery ( ) ; while ( resultSet . next ( ) ) { balance = resultSet . getInt ( 3 ) ; reservedUnits = resultSet . getInt ( 4 ) ; userexist = true ; } if ( ( reservedUnits + reservedBuff ) <= balance ) { reservedUnits = reservedUnits + reservedBuff ; psUpdBalance . setInt ( 1 , reservedUnits ) ; psUpdBalance . setString ( 2 , username ) ; int rowsUpdates = psUpdBalance . executeUpdate ( ) ; if ( rowsUpdates == Constants . ONE ) balance = reservedBuff ; } else if ( userexist ) { balance = Constants . ZERO ; } else { balance = Constants . MINUSONE ; } resultSet . close ( ) ; } return balance ; }
@param username  //Account no of the user.
@param username // Account no of the user .
// retrieve data