public <E> List<E> queryForObject(RowObjectMapper<E> rowObjectMapper, String query, Object... parameters) {

        openConnection();
        List<E> listOfE = new ArrayList<E>();
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            preparedStatement = connection.prepareStatement(query);
            int i = 1;
            for (Object parameter : parameters) {
                if (parameter instanceof String) {
                    preparedStatement.setString(i, (String) parameter);
                } else if (parameter instanceof Integer) {
                    preparedStatement.setInt(i, (Integer) parameter);
                } else if (parameter instanceof Long) {
                    preparedStatement.setLong(i, (Long) parameter);
                } else if (parameter instanceof java.util.Date) {
                    log.debug("inside template before");
                    preparedStatement.setDate(i, new java.sql.Date(((java.util.Date)parameter).getTime()));
                    log.debug("##teafter");
                }
                i++;
            }

            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()) {
                listOfE.add(rowObjectMapper.mapRowToObject(resultSet));
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {

            try {
                resultSet.close();
                preparedStatement.close();
                closeConnection();
            } catch (NullPointerException e) {
                closeConnection();
                throw new RuntimeException(e);
            } catch (SQLException e) {
                closeConnection();
                throw new RuntimeException(e);
            }


        }
        return listOfE;
    }