package info.tregmine.database.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.bukkit.inventory.ItemStack;
import org.bukkit.configuration.file.YamlConfiguration;

import info.tregmine.api.TregminePlayer;
import info.tregmine.database.ITradeDAO;
import info.tregmine.database.DAOException;

public class DBTradeDAO implements ITradeDAO
{
    private Connection conn;

    public DBTradeDAO(Connection conn)
    {
        this.conn = conn;
    }

    @Override
    public int insertTrade(int srcId, int recvId, int amount)
    throws DAOException
    {
        String sql = "INSERT INTO trade (sender_id, recipient_id, " +
            "trade_timestamp, trade_amount) ";
        sql += "VALUES (?, ?, unix_timestamp(), ?)";

        try (PreparedStatement stmt = conn.prepareStatement(sql)) {
            stmt.setInt(1, srcId);
            stmt.setInt(2, recvId);
            stmt.setInt(3, amount);
            stmt.execute();

            stmt.executeQuery("SELECT LAST_INSERT_ID()");

            try (ResultSet rs = stmt.getResultSet()) {
                if (!rs.next()) {
                    throw new DAOException("Failed to get insert_id!", sql);
                }

                return rs.getInt(1);
            }
        } catch (SQLException e) {
            throw new DAOException(sql, e);
        }
    }

    @Override
    public void insertStacks(int tradeId, ItemStack[] contents)
            throws DAOException
    {
        String sql = "INSERT INTO trade_item (trade_id, item_material, " +
            "item_data, item_meta, item_count) ";
        sql += "VALUES (?, ?, ?, ?, ?)";

        try (PreparedStatement stmt = conn.prepareStatement(sql)) {

            for (ItemStack stack : contents) {
                if (stack == null) {
                    continue;
                }

                stmt.setInt(1, tradeId);
                stmt.setInt(2, stack.getTypeId());
                stmt.setInt(3, stack.getData().getData());
                if (stack.hasItemMeta()) {
                    YamlConfiguration config = new YamlConfiguration();
                    config.set("meta", stack.getItemMeta());
                    stmt.setString(4, config.saveToString());
                }
                else {
                    stmt.setString(4, "");
                }
                stmt.setInt(5, stack.getAmount());
                stmt.execute();
            }
        } catch (SQLException e) {
            throw new DAOException(sql, e);
        }
    }

}

@@ -2567,12 +2567,657 @@
  %7D%0A    %7D
+%0A    %0A    @Override%0A    public int getAmountofTrades(int id)%0A            throws DAOException%0A    %7B%0A        String sql = %22SELECT * FROM trade_item%22;%0A        sql += %22WHERE sender_id = ?%22;%0A        %0A        try (PreparedStatement stmt = conn.prepareStatement(sql)) %7B%0A            stmt.setInt(1, id);%0A            stmt.execute();%0A            %0A            try (ResultSet rs = stmt.getResultSet()) %7B%0A                int amount = 0;%0A                while(rs.next()) %7B%0A                    amount++;%0A                %7D%0A                return amount;%0A            %7D%0A        %7D catch (SQLException e) %7B%0A            throw new DAOException(sql, e);%0A        %7D%0A    %7D
 %0A%0A%7D%0A

Update DBTradeDAO.java