KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > examples > calcserver > SqlSavingCalculator


1 package com.mockobjects.examples.calcserver;
2
3 import java.sql.PreparedStatement JavaDoc;
4 import java.sql.SQLException JavaDoc;
5
6 public class SqlSavingCalculator implements IntCalculator {
7     private IntCalculator myIntCalculator;
8     private PreparedStatement JavaDoc myStatement;
9
10
11     public SqlSavingCalculator(IntCalculator intCalculator, PreparedStatement JavaDoc preparedStatement) {
12         super();
13         myIntCalculator = intCalculator;
14         myStatement = preparedStatement;
15     }
16
17
18     public int calculate(int value1, int value2, java.lang.String JavaDoc operation) throws CalculatorException {
19         int result = myIntCalculator.calculate(value1, value2, operation);
20         try {
21             myStatement.setInt(1, result);
22             myStatement.execute();
23             return result;
24         } catch (SQLException JavaDoc ex) {
25             throw new CalculatorException(ex);
26         }
27     }
28 }
Popular Tags