/**
   * This method is used for editing the details on songs
   *
   * @param s The song that is being changed, the details are changed on the command and updated
   *     here
   * @return An integer value indicating errors or success
   */
  @Override
  public int editDetails(Song s) {
    if (s != null) {
      Connection con = null;
      PreparedStatement ps = null;

      try {
        con = getConnection();
        Blob art = con.createBlob();
        art.setBytes(1, s.getArtwork());
        String query =
            "UPDATE "
                + TABLE_NAME
                + "SET "
                + FILENAME
                + " = ?,"
                + TITLE
                + " = ?,"
                + ARTIST
                + " = ?,"
                + ALBUM
                + " = ?,"
                + GENRE
                + " = ?,"
                + YEAR
                + " = ?,"
                + PRICE
                + " = ?,"
                + LICENSE
                + " = ?,"
                + ARTWORK
                + " = ?"
                + " WHERE "
                + SONGID
                + " = ?";
        ps = con.prepareStatement(query);
        ps.setString(1, s.getFilename());
        ps.setString(2, s.getTitle());
        ps.setString(3, s.getArtist());
        ps.setString(4, s.getAlbum());
        ps.setString(5, s.getGenre());
        ps.setInt(6, s.getYear());
        ps.setDouble(7, s.getPrice());
        ps.setString(8, s.getLicense());
        ps.setBlob(9, art);
        ps.setInt(10, s.getSongId());
        int result = ps.executeUpdate();

        if (result > 0) return SUCCESS;
      } catch (SQLException ex2) {
        if (DEBUG) ex2.printStackTrace();
      } finally {
        try {
          if (ps != null) ps.close();
          if (con != null) freeConnection(con);
        } catch (SQLException e) {
          if (DEBUG) e.printStackTrace();
        }
      }
    }
    return OTHER;
  }
  /**
   * This method is used for adding a new song to the database
   *
   * @param s The song you wish to add to the database
   * @return SUCCESS if it successfully inserted, otherwise OTHER
   */
  @Override
  public int addNewSong(Song s) {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = getConnection();
      Blob data = con.createBlob();
      Blob art = con.createBlob();
      try {
        if (s.getSongdata() != null) data.setBytes(1, s.getSongdata());
        if (s.getArtwork() != null) art.setBytes(1, s.getArtwork());
      } catch (Exception e) {
        if (DEBUG) e.printStackTrace();
      }
      String query =
          "INSERT INTO "
              + TABLE_NAME
              + " ("
              + FILENAME
              + ", "
              + TITLE
              + ", "
              + ARTIST
              + ", "
              + ALBUM
              + ", "
              + GENRE
              + ", "
              + YEAR
              + ", "
              + DURATION
              + ", "
              + PRICE
              + ", "
              + LICENSE
              + ", "
              + PLAYCOUNT
              + ", "
              + UPLOADDATE
              + ", "
              + ARTWORK
              + ", "
              + SONGDATA
              + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
      ps = con.prepareStatement(query);
      ps.setString(1, s.getFilename());
      ps.setString(2, s.getTitle());
      ps.setString(3, s.getArtist());
      ps.setString(4, s.getAlbum());
      ps.setString(5, s.getGenre());
      ps.setInt(6, s.getYear());
      ps.setInt(7, s.getDuration());
      ps.setDouble(8, s.getPrice());
      ps.setString(9, s.getLicense());
      ps.setInt(10, s.getPlayCount());
      ps.setDate(11, s.getUploaded());
      ps.setBlob(12, art);
      ps.setBlob(13, data);
      if (ps.executeUpdate() > 0) return SUCCESS; // It successfully inserted into the database
    } catch (SQLException e) {
      if (DEBUG) e.printStackTrace();
    } finally {
      try {
        if (rs != null) rs.close();
        if (ps != null) ps.close();
        if (con != null) freeConnection(con);
      } catch (SQLException e) {
        if (DEBUG) e.printStackTrace();
        return SQLEX;
      }
    }
    return OTHER;
  }