?? addaction2.java
字號:
package product.action;
import product.db.*;
import java.sql.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class AddAction2 extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception
{
Connection con = null;
PreparedStatement pstmt = null;
String target = "failure";
String sql = "";
String name = request.getParameter("name");
String size = request.getParameter("size");
String unit = request.getParameter("unit");
String content = request.getParameter("content");
String product_factory = request.getParameter("product_factory");
String product_supply = request.getParameter("product_supply");
String color = request.getParameter("color");
Float price_in = Float.parseFloat(request.getParameter("price_in"));
Float price_agent = Float.parseFloat(request.getParameter("price_agent"));
Float price_sale = Float.parseFloat(request.getParameter("price_sale"));
Float price_detail = Float.parseFloat(request.getParameter("price_detail"));
String specification = request.getParameter("specification");
String note = request.getParameter("note");
sql = "insert into product(name,size,unit,content,product_factory,product_supply,"+
"color,price_in,price_agent,price_sale,price_detail,specification,note,createDay)values("+
"?,?,?,?,?,?,?,?,?,?,?,?,?,?,now())";
try{
con = DatabaseConnection.getConnection();
pstmt = con.prepareStatement(sql);
pstmt.setString(1,name);
pstmt.setString(2,size);
pstmt.setString(3,unit);
pstmt.setString(4,content);
pstmt.setString(5,product_factory);
pstmt.setString(6,product_supply);
pstmt.setString(7,color);
pstmt.setString(8,size);
pstmt.setFloat(9,price_in);
pstmt.setFloat(10,price_agent);
pstmt.setFloat(11,price_sale);
pstmt.setFloat(12,price_detail);
pstmt.setString(13,specification);
pstmt.setString(14,note);
if(pstmt.executeUpdate()==1)
target="success";
}catch(Exception e){e.printStackTrace();
}
finally{
try{
if(con!=null){
con.close();
}
}catch(Exception e2){}
}
return mapping.findForward(target);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -