@Override
    public int getVendidosTotal() {
        try{
            conn = ConnectionFactory.getConnection(); 
            String sql = "SELECT COUNT(id) AS vendidos FROM ingresso WHERE idcompra IS NOT NULL";
            ps = conn.prepareStatement(sql); 
            rs = ps.executeQuery();
            if (rs.next()) {
               int count = rs.getInt("vendidos");
               return count;
            } else {
                close(); 
                throw new RuntimeException("Não existem ingressos vendidos!"); 
            }
        } catch (SQLException e){
                throw new RuntimeException("Erro " + e.getSQLState()
                                           + " ao atualizar o objeto: " 
                                           + e.getLocalizedMessage());
        } catch (ClassNotFoundException e){
                throw new RuntimeException("Erro ao conectar ao banco: "
                                         + e.getMessage()); 
        } finally {
            close();
        } 
    }