我们最近开始使用servlet,到目前为止一直很好。我们能够完成大部分工作,但在尝试计算价格时遇到问题,请参阅下文
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
}
可以在此处找到RetrievePrice:
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;
}
}
它产生了以下错误:
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)
我们需要访问数据库并提取实际窗口类型的价格!有线索吗?