1 package com.mockobjects.examples.calcserver; 2 3 import java.sql.PreparedStatement ; 4 import java.sql.SQLException ; 5 6 public class SqlSavingCalculator implements IntCalculator { 7 private IntCalculator myIntCalculator; 8 private PreparedStatement myStatement; 9 10 11 public SqlSavingCalculator(IntCalculator intCalculator, PreparedStatement preparedStatement) { 12 super(); 13 myIntCalculator = intCalculator; 14 myStatement = preparedStatement; 15 } 16 17 18 public int calculate(int value1, int value2, java.lang.String 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 ex) { 25 throw new CalculatorException(ex); 26 } 27 } 28 } | Popular Tags |