⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addaction2.java

📁 用户可以添加商品
💻 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);
	}
    	
 }      

  	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -