1

We've recently started to work with servlets and so far so good. We're able to make most work, yet we encounter an issue when attempting to calculate a price, see below

    public int retrievePrice(int type, int height, int width) throws Exception{
    this.type = type;
    this.height = height;
    this.width = width;

    int sum = 0;
    try {

        DataAccessObject data = new DataAccessObject();

        int priceOfGlass = 300; // Price of glass per m2.
        int priceOfFrame = 0;

        int glassInSqMeters = height * width;
        int glassPrice = glassInSqMeters * priceOfGlass;

        priceOfFrame = data.retrievePrice(type);
        int framePrice = (priceOfFrame * height) + (priceOfFrame * width);

        sum = framePrice + glassPrice;
        return sum;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 45; // debugging
}

The RetrievePrice can be found here:

public class DataAccessObject  {

public int retrievePrice(int frameType) throws Exception{
    int price = 0;
    try{
        DBConnector con = new DBConnector();
        ResultSet res = con.doQuery("SELECT * FROM pricing WHERE type = "+frameType+"");
        if (res.next()) {
            price = res.getInt("price");
        }
    } catch(SQLException | ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    return price;
}

}

It's producing the following errors:

java.lang.RuntimeException: java.lang.ClassNotFoundException:     com.mysql.jdbc.Driver
at Glazier.DataAccessObject.retrievePrice(DataAccessObject.java:22)
at Calculations.retrievePrice(Calculations.java:37)
at Servlet.doGet(Servlet.java:53)

We need to access the database and pull the price of the actual window type! Any clues?

  • com.mysql.jdbc.Driver jar file missing from your project. Please add mysql-connector-java-5.1.5-bin.jar in your system path – dgk Nov 25 '16 at 11:56
  • It looks like it is already added... http://imgur.com/iD9x28f – Casper Cymback Nov 25 '16 at 12:06
  • I think you are creating in web application. If so please add in WEB-INF/lib folder. You added in your ide module and during creating war that jar file not includes in war. Or you may include this file in your server lib folder. – dgk Nov 25 '16 at 12:10
  • We solved it! We added it to the web-inf! Thank you very much! – Casper Cymback Nov 25 '16 at 12:45
  • Thanks you @casper – dgk Nov 27 '16 at 04:33

0 Answers0