Пример #1
0
  public void delete(Dictionary d) throws DAOException {
    try {
      // Create the statement with the SQL query
      PreparedStatement pState = connection.prepareStatement(REQUEST_DELETE);

      pState.setInt(1, d.getFk());
      pState.setInt(2, d.getType().getValue());
      pState.setString(3, d.getLang());

      if (log.isDebugEnabled()) {
        log.debug(pState.toString());
      }

      // Execute the SQL statement
      pState.execute();

      // Close the statement
      pState.close();
    } catch (SQLException e) {
      throw new DAOException("SQLException : " + e.getMessage());
    }
  }
Пример #2
0
  public Map<String, Dictionary> selectByFk(int fk, DictionaryType type) throws DAOException {
    Map<String, Dictionary> map = new HashMap<String, Dictionary>();

    try {
      // Create the statement with the SQL query
      PreparedStatement pState = connection.prepareStatement(REQUEST_SELECT_BY_FK);

      pState.setInt(1, fk);
      pState.setInt(2, type.getValue());

      if (log.isDebugEnabled()) {
        log.debug(pState.toString());
      }

      // Execute the SQL statement
      ResultSet result = pState.executeQuery();

      // Put each result in the map
      while (result.next()) {
        Dictionary d = resultToDictionary(result);

        map.put(d.getLang(), d);
      }

      // Close the result and the statement
      try {
        result.close();
      } finally {
        pState.close();
      }
    } catch (SQLException e) {
      throw new DAOException("SQLException : " + e.getMessage());
    }

    return map;
  }