我正在尝试在我的JEE项目中调用DAO方法,在MySQL中创建一个表。
以下是代码的外观:
@Override
String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException {
int height = Integer.parseInt(request.getParameter("height"));
int length = Integer.parseInt(request.getParameter("length"));
int width = Integer.parseInt(request.getParameter("width"));
LegoHouseAlgorithm lego = new LegoHouseAlgorithm();
ArrayList<Integer> bricks = lego.calc(height, length, width);
request.setAttribute("longbrick", Integer.toString(bricks.get(0)));
request.setAttribute("mediumbrick", Integer.toString(bricks.get(1)));
request.setAttribute("shortbrick", Integer.toString(bricks.get(2)));
request.setAttribute("wall3", Integer.toString(bricks.get(3)));
request.setAttribute("wall4", Integer.toString(bricks.get(4)));
request.setAttribute("wall5", Integer.toString(bricks.get(5)));
int finalLongBrick = (bricks.get(0) + bricks.get(3)) * 2;
int finalMediumBrick = (bricks.get(1) + bricks.get(4)) * 2;
int finalShortBrick = (bricks.get(2) + bricks.get(5)) * 2;
request.setAttribute("finallongbrick", finalLongBrick);
request.setAttribute("finalmediumbrick", finalMediumBrick);
request.setAttribute("finalshortbrick", finalShortBrick);
try {
LogicFacade.makeOrder(height, length, width);
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(Order.class.getName()).log(Level.SEVERE, null, ex);
}
return "order";
我正在使用抽象类的自定义框架来确定调用堆栈:
public static OrderSample makeOrder(int height, int length, int width) throws SQLException, ClassNotFoundException, LoginSampleException{
OrderSample order = new OrderSample(height, width, length);
UserMapper.createOrder(order);
return order;
}
public static void createOrder (OrderSample order) throws SQLException, ClassNotFoundException, LoginSampleException{
try{
Connection con = Connector.connection();
String SQL = "INSERT INTO orders (height, length, width) VALUES (?, ?, ?)";
PreparedStatement ps = con.prepareStatement(SQL);
ps.setInt(order.getHeigh(), 1);
ps.setInt(order.getLength(), 2);
ps.setInt(order.getWidth(), 3);
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
rs.next();
int id = rs.getInt(1);
order.setId(id);
} catch ( ClassNotFoundException | SQLException ex ) {
throw new LoginSampleException(ex.getMessage());
}
}
whatevr参数我输入我的html表单我得到错误:
Parameter index out of range ((inserted number) > number of parameters, which is 3).