16.10.2015 Views

Getting Startedwith pureQuery

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 12 – Stored Procedures 257<br />

// Ask the user for the maximum department sum.<br />

Double bonusMaxSumForDepartment = null;<br />

while (null == bonusMaxSumForDepartment) {<br />

String bonusMaxSumForDepartmentString = getLineFromConsole<br />

("Employee bonuses will be automatically modified, as long as\n"<br />

+ "the total of the bonuses in a department does not exceed\n"<br />

+ "some limit that you set. Please enter the limit that<br />

you\nwant the application to use: ");<br />

try {<br />

bonusMaxSumForDepartment = Double.parseDouble<br />

(bonusMaxSumForDepartmentString);<br />

}<br />

catch (NumberFormatException e) {<br />

outputWriter.println ("The value \"" + bonusFactor + "\" is not<br />

a valid number.");<br />

}<br />

}<br />

// Create a map for the parameters.<br />

Map parameters = new HashMap ();<br />

parameters.put ("bonusFactor", bonusFactor);<br />

parameters.put ("bonusMaxSumForDepartment",<br />

bonusMaxSumForDepartment);<br />

Iterator employees = null;<br />

try {<br />

// Execute the bonus_increase stored procedure and get the query<br />

// result, which contains the bonuses for all the employees.<br />

employees = data.callBonusIncrease (parameters);<br />

// Get the values of the OUT parameters from bonus_increase.<br />

String departmentsWithoutNewBonuses = (String) parameters.get<br />

("departmentsWithoutNewBonuses");<br />

int countDepartmentsViewed = (Integer) parameters.get<br />

("countDepartmentsViewed");<br />

int countDepartmentsBonusChanged = (Integer) parameters.get<br />

("countDepartmentsBonusChanged");<br />

String errorMessage = (String) parameters.get ("errorMessage");<br />

a map<br />

// We will display the total of bonuses in each department. Create<br />

// containing the totals.<br />

TreeMap bonusesByDepartment = null;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!