@Override public int addExpense(Expense expense) throws SQLException { insertStatement = connection.prepareStatement(INSERT); insertStatement.clearParameters(); insertStatement.setInt(1, expense.getNum()); insertStatement.setDate(2, expense.getPaydate()); insertStatement.setInt(3, expense.getReceiver()); insertStatement.setInt(4, expense.getValue()); int result = insertStatement.executeUpdate(); return result; }
@Override public int updateExpense(int num, Expense expense) throws SQLException { updateByNumStatement = connection.prepareStatement(UPDATE_BY_NUM); updateByNumStatement.clearParameters(); updateByNumStatement.setDate(1, expense.getPaydate()); updateByNumStatement.setInt(2, expense.getReceiver()); updateByNumStatement.setInt(3, expense.getValue()); updateByNumStatement.setInt(4, num); int result = updateByNumStatement.executeUpdate(); return result; }
@Override public ArrayList<Expense> getExpenses() throws SQLException { selectAllStatement = connection.createStatement(); ArrayList<Expense> list = new ArrayList<Expense>(); ResultSet result = selectAllStatement.executeQuery(SELECT_ALL); while (result.next()) { Expense expense = new Expense(); expense.setNum(result.getInt("num")); expense.setPaydate(result.getDate("paydate")); expense.setReceiver(result.getInt("receiver")); expense.setValue(result.getInt("value")); list.add(expense); } return list; }