JSP(9) - 增加商品模組

zhyuh發表於2005-06-14

以下模組無要點技術資訊,放在此處僅為系統的完整性考慮。

該模組增加商品種類資訊。

[@more@]

add_comm_bef.jsp:





response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader("Expires", 0); //prevents caching at the proxy server

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Date d = new Date();
DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE);
%>







增加商品







<!--

--&gt




增加商品


商品編號:     

商品名稱:     

商品類別:     

單價:         

庫存數量:     

顏色:         

尺寸:         

最後修改日起:


           






add_comm_aft.jsp:





增加商品資訊



String sCommID = request.getParameter("comm_id");
String sCommName = request.getParameter("comm_name");
String sCommCate = request.getParameter("comm_type");
String sCommUnit = request.getParameter("comm_unit");
String sCommColor = request.getParameter("comm_color");
String sCommSize = request.getParameter("comm_size");
String sCommUptDate = request.getParameter("comm_upt_date");

String sCommID2 = new String(sCommID.getBytes("iso-8859-1"),"GBK");
String sCommName2 = new String(sCommName.getBytes("iso-8859-1"),"GBK");
String sCommCate2 = new String(sCommCate.getBytes("iso-8859-1"),"GBK");
String sCommColor2 = new String(sCommColor.getBytes("iso-8859-1"),"GBK");
String sCommSize2 = new String(sCommSize.getBytes("iso-8859-1"),"GBK");

if (sCommID.equals("")){
throw new Exception("商品編號不準為空");
}
if (sCommName.equals("")){
throw new Exception("商品名稱不準為空");
}

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@TCSCH074.tcsgdccn.com:1521:orcl";
//orcl為你的資料庫的SID
String user="store";
String password="store";
Connection conn= DriverManager.getConnection(url,user,password);
String sInsert = null;
Statement stmt = null;


String sCommQutt = request.getParameter("comm_qutt");

try{
sInsert = "insert into commodity (comm_id, comm_name, comm_cate, comm_unit, comm_qutt,";
sInsert = sInsert + "comm_upt_date, comm_color, comm_size) values(";
sInsert = sInsert + "'"+sCommID2+"','"+sCommName2+"','"+sCommCate2+"','"+sCommUnit;
sInsert = sInsert + "',"+sCommQutt +",to_date('"+sCommUptDate+"','yyyy-mm-dd'),'"+sCommColor2+"','"+sCommSize2+"')";
//out.println(sInsert);
stmt = conn.createStatement();
stmt.execute(sInsert);
conn.commit();
out.println("增加商品"+sCommName2+"完成。");
}

catch (Exception e){
System.out.println("增加商品失敗!");
e.printStackTrace();
out.println("增加商品失敗!
");
out.println(e.getMessage());
out.println("

");
}

finally {
if (stmt != null) stmt.close();
conn.close();
}
%>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/207/viewspace-800202/,如需轉載,請註明出處,否則將追究法律責任。

相關文章