JSP(10) - 修改商品資訊模組

zhyuh發表於2005-06-14
該模組類似於 修改客戶資訊模組(http://blog.itpub.net/post/334/31813)[@more@]

upt_comm1.jsp:



<br>請輸入要修改的商品的編號


<!----&gt



請輸入要修改的商品編號

          type="button" value="取消" name="cancel">




upt_comm2.jsp:







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






修改商品資訊




String sCommID = request.getParameter("comm_id");
String sCommName = "";
String sCommCate = "";
String sCommUnit = null;
String sCommQutt = null;
String sCommUptDt = null;
String sCommColor = "";
String sCommSize = "";


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);
ResultSet rs = null;
String sQuery = null;
Statement stmt = null;


try {
sQuery = "select COMM_ID, COMM_NAME, COMM_CATE, COMM_UNIT, COMM_QUTT,";
sQuery = sQuery + "to_char(COMM_UPT_DATE,'yyyy-mm-dd') COMM_UPT_DATE, COMM_COLOR, COMM_SIZE ";
sQuery = sQuery + "from commodity where comm_id = '"+sCommID+"'";

stmt = conn.createStatement();
rs = stmt.executeQuery(sQuery);

while(rs.next())
{
sCommID = rs.getString("COMM_ID");
sCommName = rs.getString("COMM_NAME");
sCommCate = rs.getString("COMM_CATE");
if (sCommCate==null) sCommCate="";
sCommUnit = rs.getString("COMM_UNIT");
sCommQutt = rs.getString("COMM_QUTT");
sCommUptDt = rs.getString("COMM_UPT_DATE");
sCommColor = rs.getString("COMM_COLOR");
if (sCommColor==null) sCommColor="";
sCommSize = rs.getString("COMM_SIZE");
if (sCommSize==null) sCommSize="";
}

rs.close();
stmt.close();
conn.close();
}

catch (Exception e){
System.out.println("檢索商品資訊失敗!");
e.printStackTrace();
out.println("

檢索商品資訊失敗!

");
out.println( e.getMessage() );
}

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

%>


修改商品資訊


商品編號: 

商品名稱: 

類別:     

單價:     

顏色:     

尺寸:     

庫存:     

修改日起:


           







upt_comm3.jsp:







String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>




修改商品資訊




String sCommID = request.getParameter("comm_id");
String sCommName = request.getParameter("comm_name");
String sCommCate = request.getParameter("comm_cate");
String sCommUnit = request.getParameter("comm_unit");
String sCommQutt = request.getParameter("comm_qutt");
String sCommUptDt = request.getParameter("comm_upt_date");
String sCommColor = request.getParameter("comm_color");
String sCommSize = request.getParameter("comm_size");

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");

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 sUpdate = null;
Statement stmt = null;

try{

sUpdate = "update commodity set comm_cate='"+sCommCate2+
"',comm_unit="+sCommUnit+
",comm_color='"+sCommColor2+
"',comm_size='"+sCommSize2+
"',comm_upt_date=to_date('"+sCommUptDt+
"','yyyy-mm-dd') where comm_id='"+sCommID2+"'";

//out.println(sUpdate+"
");
stmt = conn.createStatement();
stmt.execute(sUpdate);
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-800203/,如需轉載,請註明出處,否則將追究法律責任。

相關文章