? equals = myPojoProviderService.getAllMyPojos()

It works, now just to apply the specific Vaadin 8 code to populate the Vaadin Grid.

You can co-edit with me, if you desire.
https://zoom.us/j/574115666

Would I follow this one to reference my DAO bean?

https://www.voxxed.com/blog/2017/03/21-improvements-vaadin-8/

31907.png

Video notes
https://www.useloom.com/share/8f6231b9766a4f2385a6121898f007b6

        List<Product> products = Backend.getProducts();
        Grid<Product> grid = new Grid<>(Product.class);
        grid.setItems(products);

31908.png

Import List and Grid - just click on the type, hit F2 and let Eclipse find the dependencies. Make sure to use java.util.List for the List (not java.awt.List).

Replace Backend with an instance of your DAO.

Modified MainUI.java with import com.vaadin.ui.Grid;

only two errors remain

List
Backend

[code]
       List<Product> products = Backend.getProducts();
[/code]

31909.png

Excellent. The Backend replacement is not working:

package com.dataSQL.basic;

import java.util.List;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;


@Theme("maintheme")
public class MainUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {  
        List<Product> products = ProductDbUtil.getProducts();
        Grid<Product> grid = new Grid<>(Product.class);
        grid.setItems(products);        
    }

    @WebServlet(urlPatterns = "/*", name = "MainUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MainUI.class, productionMode = false)
    public static class MainUIServlet extends VaadinServlet {
    }
}

31910.png

The error message

31911.png

Create an instance of ProductDbUtil - use new, or call getInstance() if you have a factory method.

Thank you, you have been the best help I have received. I had hoped to populate a Vaadin Grid, but I am a lot closer than before. Thank you.

That

“Create an instance of ProductDbUtil - use new, or call getInstance() if you have a factory method.”

is nowhere, not done or mentioned in the examples

https://www.voxxed.com/blog/2017/03/21-improvements-vaadin-8/

but shall explore to discover.

https://docs.oracle.com/javase/tutorial/reflect/member/ctorInstance.html

Once again, I really thank you for the time you have shared with me – way above and beyond what was hoped for, thank you!

Hello, Alejandro. I am paying for a course in java Design Patterns to include 24:

Decorator, Factory, Abstract Factory, Strategy, Singleton, Adapter, Facade, Template, Iterator, MVC, Observer, Command, Composite, Builder, Chain of Responsibility, Memento, Visitor, State, Flyweight, Bridge, Mediator, Prototype, Proxy, Double-Checked Locking and Dependency Injection.

Would this lead to my understanding and ability to complete the coding to view a Vaadin Grid with my remote data, as a beginning? My immediate focus is to create a Vaadin Grid with my remote data, then go through the Book of Vaadin 8 to learn all about Vaadin using real examples, beginning from the Vaadin Grid and leading to Vaadin Designer.

Please, would taking the design pattern course enable me to resolve my current coding challenge with creating the instance?

I don’t think that this is a design pattern issue, but just a few minor misunderstandings about Java. Can you post the code for the DC util class? I think that you are inches from the goal.

Wow, thank you! I have spent the last 4 hours posting to instructors about Java Patterns, seeking WHICH additional course to buy. I really want to spend my time reading the Book of Vaadin and LEARN Vaadin. I have instructors that I shall learn Java Architechture from. Everything you have generously shared with me, shall be printed and placed in my Vaadin coding note book.

What would you like me to post?

Shall post all three:
Model
Controller
DAO

plus the Vaadin Archetype MainUI.java

Four files.

One moment, please…

and Thank you.!

model

package com.dataSQL.basic;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Product {

    private int id;    
    private String small_desc;
    private String large_desc;
    private String sku;
    private String category;
    private String barcode;    
    
    public Product() {
    }
    
    public Product(int id, String small_desc, String large_desc, String sku, String category, String barcode) {            
        this.id = id;        
        this.small_desc = small_desc;
        this.large_desc = large_desc;        
        this.sku = sku;
        this.category = category;
        this.barcode = barcode;         
    }
        
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getSmall_desc() {
        return small_desc;
    }

    public void setSmall_desc(String small_desc) {
        this.small_desc = small_desc;
    }

    public String getLarge_desc() {
        return large_desc;
    }

    public void setLarge_desc(String large_desc) {
        this.large_desc = large_desc;
    }

    public String getSku() {
        return sku;
    }

    public void setSku(String sku) {
        this.sku = sku;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getBarcode() {
        return barcode;
    }

    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

    @Override
    public String toString() {
        return "Product [id=" + id                
                + ", small_desc=" + small_desc
                + ", large_desc=" + large_desc                
                + ", sku=" + sku
                + ", category=" + category                
                + ", barcode=" + barcode + "]";
    }

}


Controller

package com.dataSQL.basic;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class ProductController {

    private List<Product> products;
    private ProductDbUtil productDbUtil;
    private Logger logger = Logger.getLogger(getClass().getName());
    
    public ProductController() throws Exception {
        products = new ArrayList<>();
        
        productDbUtil = ProductDbUtil.getInstance();
    }
    
    public List<Product> getProducts() {
        return products;
    }

    public void loadProducts() {

        logger.info("Loading products");
        
        products.clear();

        try {
            
            // get all products from database
            products = productDbUtil.getProducts();
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error loading products", exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
        }
    }
        
    public String addProduct(Product theProduct) {

        logger.info("Adding product: " + theProduct);

        try {
            
            // add product to the database
            productDbUtil.addProduct(theProduct);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error adding products", exc);
            
            // add error message for JSF page
            addErrorMessage(exc);

            return null;
        }
        
        return "list-products?faces-redirect=true";
    }

    public String loadProduct(int productId) {
        
        logger.info("loading product: " + productId);
        
        try {
            // get product from database
            Product theProduct = productDbUtil.getProduct(productId);
            
            // put in the request attribute ... so we can use it on the form page
            ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();        

            Map<String, Object> requestMap = externalContext.getRequestMap();
            requestMap.put("product", theProduct);    
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error loading product id:" + productId, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
                
        return "update-product-form.xhtml";
    }    
    
    public String updateProduct(Product theProduct) {

        logger.info("updating product: " + theProduct);
        
        try {
            
            // update product in the database
            productDbUtil.updateProduct(theProduct);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error updating product: " + theProduct, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
        
        return "list-products?faces-redirect=true";        
    }
    
    public String deleteProduct(int productId) {

        logger.info("Deleting product id: " + productId);
        
        try {

            // delete the product from the database
            productDbUtil.deleteProduct(productId);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error deleting product id: " + productId, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
        
        return "list-products";    
    }    
    
    private void addErrorMessage(Exception exc) {
        FacesMessage message = new FacesMessage("Error: " + exc.getMessage());
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
    
}
[/code]DAO


[code]
package com.dataSQL.basic;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ProductDbUtil {

    private static ProductDbUtil instance;
    private DataSource dataSource;
    private String jndiName = "java:comp/env/jdbc/webdata";
    
    public static ProductDbUtil getInstance() throws Exception {
        if (instance == null) {
            instance = new ProductDbUtil();
        }
        
        return instance;
    }
    
    private ProductDbUtil() throws Exception {        
        dataSource = getDataSource();
    }

    private DataSource getDataSource() throws NamingException {
        Context context = new InitialContext();
        
        DataSource theDataSource = (DataSource) context.lookup(jndiName);
        
        return theDataSource;
    }
        
    public List<Product> getProducts() throws Exception {

        List<Product> products = new ArrayList<>();

        Connection myConn = null;
        Statement myStmt = null;
        ResultSet myRs = null;
        
        try {
            myConn = getConnection();

            String sql = "select * from product order by category";

            myStmt = myConn.createStatement();

            myRs = myStmt.executeQuery(sql);

            // process result set
            while (myRs.next()) {
                
                // retrieve data from result set row
                int id = myRs.getInt("id");                            
                String small_desc = myRs.getString("small_desc");
                String large_desc = myRs.getString("large_desc");
                String sku = myRs.getString("sku");                
                String category = myRs.getString("category");
                String barcode = myRs.getString("barcode");                
                

                // create new product object
                Product tempProduct = new Product(id, small_desc, large_desc, sku, category, barcode);

                // add it to the list of products
                products.add(tempProduct);
            }
            
            return products;        
        }
        finally {
            close (myConn, myStmt, myRs);
        }
    }

    public void addProduct(Product theProduct) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "insert into product (small_desc, large_desc, sku, category, barcode) values (?, ?, ?, ?, ?)";

            myStmt = myConn.prepareStatement(sql);

            // set params
            myStmt.setString(1, theProduct.getSmall_desc());
            myStmt.setString(2, theProduct.getLarge_desc());
            myStmt.setString(3, theProduct.getSku());
            myStmt.setString(4, theProduct.getCategory());
            myStmt.setString(5, theProduct.getBarcode());            
            myStmt.execute();            
        }
        finally {
            close (myConn, myStmt);
        }
        
    }
    
    public Product getProduct(int productId) throws Exception {
    
        Connection myConn = null;
        PreparedStatement myStmt = null;
        ResultSet myRs = null;
        
        try {
            myConn = getConnection();

            String sql = "select * from product where id=?";

            myStmt = myConn.prepareStatement(sql);
            
            // set params
            myStmt.setInt(1, productId);
            
            myRs = myStmt.executeQuery();

            Product theProduct = null;
            
            // retrieve data from result set row
            if (myRs.next()) {
                int id = myRs.getInt("id");
                String small_desc = myRs.getString("small_desc");
                String large_desc = myRs.getString("large_desc");                
                String sku = myRs.getString("sku");
                String category = myRs.getString("category");                
                String barcode = myRs.getString("barcode");                

                theProduct = new Product(id, small_desc, large_desc, sku, category, barcode);
            }
            else {
                throw new Exception("Could not find product id: " + productId);
            }

            return theProduct;
        }
        finally {
            close (myConn, myStmt, myRs);
        }
    }
    
    public void updateProduct(Product theProduct) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "update product "
                        + " set small_desc=?, large_desc=?, sku=?, category=?, barcode=?"
                        + " where id=?";

            myStmt = myConn.prepareStatement(sql);

            // set params            
            myStmt.setString(1, theProduct.getSmall_desc());
            myStmt.setString(2, theProduct.getLarge_desc());
            myStmt.setString(3, theProduct.getSku());
            myStmt.setString(4, theProduct.getCategory());
            myStmt.setString(5, theProduct.getBarcode());            
            myStmt.execute();
        }
        finally {
            close (myConn, myStmt);
        }
        
    }
    
    public void deleteProduct(int productId) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "delete from product where id=?";

            myStmt = myConn.prepareStatement(sql);

            // set params
            myStmt.setInt(1, productId);
            
            myStmt.execute();
        }
        finally {
            close (myConn, myStmt);
        }        
    }    
    
    private Connection getConnection() throws Exception {

        Connection theConn = dataSource.getConnection();
        
        return theConn;
    }
    
    private void close(Connection theConn, Statement theStmt) {
        close(theConn, theStmt, null);
    }
    
    private void close(Connection theConn, Statement theStmt, ResultSet theRs) {

        try {
            if (theRs != null) {
                theRs.close();
            }

            if (theStmt != null) {
                theStmt.close();
            }

            if (theConn != null) {
                theConn.close();
            }
            
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }    
}
[/code]
Vaadin 8 Archetype MainUI.java[code]
package com.dataSQL.basic;

import java.util.List;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Grid;
import com.vaadin.ui.UI;

@Theme("maintheme")
public class MainUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {  
        List<Product> products = ProductDbUtil.getProducts();
        Grid<Product> grid = new Grid<>(Product.class);
        grid.setItems(products);        
    }

    @WebServlet(urlPatterns = "/*", name = "MainUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MainUI.class, productionMode = false)
    public static class MainUIServlet extends VaadinServlet {
    }
}

32006.png

In the MainUI init() method, have you tried

List products = ProductDbUtil.getInstance().getProducts();

?

Hello, sorry for the tardy response.

Shall try now.

did not work…

Multiple markers at this line
- Unhandled exception type Exception
- Unhandled exception type Exception

31912.png
31913.png

model

package com.dataSQL.basic;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Product {

    private int id;    
    private String small_desc;
    private String large_desc;
    private String sku;
    private String category;
    private String barcode;    
    
    public Product() {
    }
    
    public Product(int id, String small_desc, String large_desc, String sku, String category, String barcode) {            
        this.id = id;        
        this.small_desc = small_desc;
        this.large_desc = large_desc;        
        this.sku = sku;
        this.category = category;
        this.barcode = barcode;         
    }
        
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getSmall_desc() {
        return small_desc;
    }

    public void setSmall_desc(String small_desc) {
        this.small_desc = small_desc;
    }

    public String getLarge_desc() {
        return large_desc;
    }

    public void setLarge_desc(String large_desc) {
        this.large_desc = large_desc;
    }

    public String getSku() {
        return sku;
    }

    public void setSku(String sku) {
        this.sku = sku;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getBarcode() {
        return barcode;
    }

    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

    @Override
    public String toString() {
        return "Product [id=" + id                
                + ", small_desc=" + small_desc
                + ", large_desc=" + large_desc                
                + ", sku=" + sku
                + ", category=" + category                
                + ", barcode=" + barcode + "]";
    }

}


Controller

package com.dataSQL.basic;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class ProductController {

    private List<Product> products;
    private ProductDbUtil productDbUtil;
    private Logger logger = Logger.getLogger(getClass().getName());
    
    public ProductController() throws Exception {
        products = new ArrayList<>();
        
        productDbUtil = ProductDbUtil.getInstance();
    }
    
    public List<Product> getProducts() {
        return products;
    }

    public void loadProducts() {

        logger.info("Loading products");
        
        products.clear();

        try {
            
            // get all products from database
            products = productDbUtil.getProducts();
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error loading products", exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
        }
    }
        
    public String addProduct(Product theProduct) {

        logger.info("Adding product: " + theProduct);

        try {
            
            // add product to the database
            productDbUtil.addProduct(theProduct);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error adding products", exc);
            
            // add error message for JSF page
            addErrorMessage(exc);

            return null;
        }
        
        return "list-products?faces-redirect=true";
    }

    public String loadProduct(int productId) {
        
        logger.info("loading product: " + productId);
        
        try {
            // get product from database
            Product theProduct = productDbUtil.getProduct(productId);
            
            // put in the request attribute ... so we can use it on the form page
            ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();        

            Map<String, Object> requestMap = externalContext.getRequestMap();
            requestMap.put("product", theProduct);    
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error loading product id:" + productId, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
                
        return "update-product-form.xhtml";
    }    
    
    public String updateProduct(Product theProduct) {

        logger.info("updating product: " + theProduct);
        
        try {
            
            // update product in the database
            productDbUtil.updateProduct(theProduct);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error updating product: " + theProduct, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
        
        return "list-products?faces-redirect=true";        
    }
    
    public String deleteProduct(int productId) {

        logger.info("Deleting product id: " + productId);
        
        try {

            // delete the product from the database
            productDbUtil.deleteProduct(productId);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error deleting product id: " + productId, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
        
        return "list-products";    
    }    
    
    private void addErrorMessage(Exception exc) {
        FacesMessage message = new FacesMessage("Error: " + exc.getMessage());
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
    
}
[/code]DAO


[code]
package com.dataSQL.basic;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ProductDbUtil {

    private static ProductDbUtil instance;
    private DataSource dataSource;
    private String jndiName = "java:comp/env/jdbc/webdata";
    
    public static ProductDbUtil getInstance() throws Exception {
        if (instance == null) {
            instance = new ProductDbUtil();
        }
        
        return instance;
    }
    
    private ProductDbUtil() throws Exception {        
        dataSource = getDataSource();
    }

    private DataSource getDataSource() throws NamingException {
        Context context = new InitialContext();
        
        DataSource theDataSource = (DataSource) context.lookup(jndiName);
        
        return theDataSource;
    }
        
    public List<Product> getProducts() throws Exception {

        List<Product> products = new ArrayList<>();

        Connection myConn = null;
        Statement myStmt = null;
        ResultSet myRs = null;
        
        try {
            myConn = getConnection();

            String sql = "select * from product order by category";

            myStmt = myConn.createStatement();

            myRs = myStmt.executeQuery(sql);

            // process result set
            while (myRs.next()) {
                
                // retrieve data from result set row
                int id = myRs.getInt("id");                            
                String small_desc = myRs.getString("small_desc");
                String large_desc = myRs.getString("large_desc");
                String sku = myRs.getString("sku");                
                String category = myRs.getString("category");
                String barcode = myRs.getString("barcode");                
                

                // create new product object
                Product tempProduct = new Product(id, small_desc, large_desc, sku, category, barcode);

                // add it to the list of products
                products.add(tempProduct);
            }
            
            return products;        
        }
        finally {
            close (myConn, myStmt, myRs);
        }
    }

    public void addProduct(Product theProduct) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "insert into product (small_desc, large_desc, sku, category, barcode) values (?, ?, ?, ?, ?)";

            myStmt = myConn.prepareStatement(sql);

            // set params
            myStmt.setString(1, theProduct.getSmall_desc());
            myStmt.setString(2, theProduct.getLarge_desc());
            myStmt.setString(3, theProduct.getSku());
            myStmt.setString(4, theProduct.getCategory());
            myStmt.setString(5, theProduct.getBarcode());            
            myStmt.execute();            
        }
        finally {
            close (myConn, myStmt);
        }
        
    }
    
    public Product getProduct(int productId) throws Exception {
    
        Connection myConn = null;
        PreparedStatement myStmt = null;
        ResultSet myRs = null;
        
        try {
            myConn = getConnection();

            String sql = "select * from product where id=?";

            myStmt = myConn.prepareStatement(sql);
            
            // set params
            myStmt.setInt(1, productId);
            
            myRs = myStmt.executeQuery();

            Product theProduct = null;
            
            // retrieve data from result set row
            if (myRs.next()) {
                int id = myRs.getInt("id");
                String small_desc = myRs.getString("small_desc");
                String large_desc = myRs.getString("large_desc");                
                String sku = myRs.getString("sku");
                String category = myRs.getString("category");                
                String barcode = myRs.getString("barcode");                

                theProduct = new Product(id, small_desc, large_desc, sku, category, barcode);
            }
            else {
                throw new Exception("Could not find product id: " + productId);
            }

            return theProduct;
        }
        finally {
            close (myConn, myStmt, myRs);
        }
    }
    
    public void updateProduct(Product theProduct) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "update product "
                        + " set small_desc=?, large_desc=?, sku=?, category=?, barcode=?"
                        + " where id=?";

            myStmt = myConn.prepareStatement(sql);

            // set params            
            myStmt.setString(1, theProduct.getSmall_desc());
            myStmt.setString(2, theProduct.getLarge_desc());
            myStmt.setString(3, theProduct.getSku());
            myStmt.setString(4, theProduct.getCategory());
            myStmt.setString(5, theProduct.getBarcode());            
            myStmt.execute();
        }
        finally {
            close (myConn, myStmt);
        }
        
    }
    
    public void deleteProduct(int productId) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "delete from product where id=?";

            myStmt = myConn.prepareStatement(sql);

            // set params
            myStmt.setInt(1, productId);
            
            myStmt.execute();
        }
        finally {
            close (myConn, myStmt);
        }        
    }    
    
    private Connection getConnection() throws Exception {

        Connection theConn = dataSource.getConnection();
        
        return theConn;
    }
    
    private void close(Connection theConn, Statement theStmt) {
        close(theConn, theStmt, null);
    }
    
    private void close(Connection theConn, Statement theStmt, ResultSet theRs) {

        try {
            if (theRs != null) {
                theRs.close();
            }

            if (theStmt != null) {
                theStmt.close();
            }

            if (theConn != null) {
                theConn.close();
            }
            
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }    
}
[/code]
Vaadin 8 Archetype MainUI.java[code]
package com.dataSQL.basic;

import java.util.List;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Grid;
import com.vaadin.ui.UI;

@Theme("maintheme")
public class MainUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {  
        List<Product> products = ProductDbUtil.getProducts();
        Grid<Product> grid = new Grid<>(Product.class);
        grid.setItems(products);        
    }

    @WebServlet(urlPatterns = "/*", name = "MainUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MainUI.class, productionMode = false)
    public static class MainUIServlet extends VaadinServlet {
    }
}

Wrap it in a
try-catch block
. You can also have Eclipse do it for you by hitting F2 with the cursor over the code with the red squiggly line.

Are you well acquainted with Java fundamentals? If not, and given that you are considering taking courses, I think it would be worthwhile to get the rudiments down solid. Creating instances and handling exceptions are common Java operations, and it would reduce the number of round trips when you are asking for help on these forums. It will also help you to better understand the code examples given on the
blog posts that you have referenced
. The post is actually quite self-explanatory, however the sample is not meant to be cut-and-pasted into your IDE; the writer expects the reader to adapt it to their own environment.

Just a suggestion.

– AC

Shall be taking Java course to expand upon all that you have shared with me.

I found the solution, but do not know how to implement it

You need to create an instance of the object first using the “new” keyword, then call the method.

but do not know how to implement it to the following code:

[code]
package com.dataSQL.basic;

import java.util.List;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Grid;
import com.vaadin.ui.UI;

@Theme("maintheme")
public class MainUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {  
        
        
        List<Product> products = ProductDbUtil.getProducts();
        
        Grid<Product> grid = new Grid<>(Product.class);
        grid.setItems(products);        
    }

    @WebServlet(urlPatterns = "/*", name = "MainUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MainUI.class, productionMode = false)
    public static class MainUIServlet extends VaadinServlet {
    }
}
[/code]

31915.png