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?