JSP(5) - 修改客戶資訊模組
分三頁。先按顧客編號檢索出顧客資訊,修改顧客資訊後存入資料庫。
要點:
1) 從資料庫檢索出資料,用
ResultSet rs = null;
......
stmt = conn.createStatement();
rs = stmt.executeQuery(sQuery);
while(rs.next()) { ...... }
upt_cust1.jsp:
請輸入要修改的顧客的卡號
<!---->
upt_cust2.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 sCustID = request.getParameter("cust_id");
String sCustName = null;
String sCustSex = null;
String sCustYear = null;
String sCustMonth = null;
String sCustAddr = null;
String sCustZip = null;
String sCustPhOff = null;
String sCustPhHom = null;
String sCustMobile = null;
String sCustEmail = null;
String sCustDis = null;
String sCustTtSum = null;
String sCustCrtDt = null;
String sCustUptDt = null;
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 cst_id, cst_name, cst_sex, cst_year, to_number(cst_month) cst_month, cst_address, cst_zip_code, ";
sQuery = sQuery + "cst_ph_office, cst_ph_home, cst_mobile, cst_email, cst_discount, ";
sQuery = sQuery + "cst_trd_sum, to_char(cst_crt_date,'yyyy-mm-dd') cst_crt_dt from customer where cst_id = '"+sCustID+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sQuery);
while(rs.next())
{
sCustID = rs.getString("cst_id");
sCustName = rs.getString("cst_name");
sCustSex = rs.getString("cst_sex");
sCustYear = rs.getString("cst_year");
if (sCustYear==null) sCustYear="";
sCustMonth = rs.getString("cst_month");
if (sCustMonth==null) sCustMonth="";
sCustAddr = rs.getString("cst_address");
if (sCustAddr==null) sCustAddr="";
sCustZip = rs.getString("cst_zip_code");
if (sCustZip==null) sCustZip="";
sCustPhOff = rs.getString("cst_ph_office");
if (sCustPhOff==null) sCustPhOff="";
sCustPhHom = rs.getString("cst_ph_home");
if (sCustPhHom==null) sCustPhHom="";
sCustMobile = rs.getString("cst_mobile");
if (sCustMobile==null) sCustMobile="";
sCustEmail = rs.getString("cst_email");
if (sCustEmail==null) sCustEmail="";
sCustDis = rs.getString("cst_discount");
sCustTtSum = rs.getString("cst_trd_sum");
sCustCrtDt = rs.getString("cst_crt_dt");
}
//out.println(sCustSex);
if (sCustSex.equals("M")) {
sCustSex="男";
}
else if (sCustSex.equals("F")){
sCustSex = "女";
}
else {
sCustSex ="";
}
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_cust3.jsp:
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
String sCustID = request.getParameter("cust_id");
String sCustName = request.getParameter("cust_name");
String sCustSex = request.getParameter("cust_sex");
String sCustYear = request.getParameter("cust_year");
String sCustMonth = request.getParameter("cust_month");
String sCustAddr = request.getParameter("cust_addr");
String sCustZip = request.getParameter("cust_zip");
String sCustPhOff = request.getParameter("cust_ph_office");
String sCustPhHom = request.getParameter("cust_ph_home");
String sCustMobile = request.getParameter("cust_mobile");
String sCustEmail = request.getParameter("cust_email");
Float fCustDis = Float.valueOf(request.getParameter("cust_discount"));
String sCustTtSum = request.getParameter("cust_trd_sum");
String sCustCrtDt = request.getParameter("cust_crt_date");
String sCustUptDt = request.getParameter("cust_upt_date");
String sCustID2 = new String(sCustID.getBytes("iso-8859-1"),"GBK");
String sCustName2 = new String(sCustName.getBytes("iso-8859-1"),"GBK");
String sCustAddr2 = new String(sCustAddr.getBytes("iso-8859-1"),"GBK");
String sCustPhOff2 = new String(sCustPhOff.getBytes("iso-8859-1"),"GBK");
String sCustPhHom2 = new String(sCustPhHom.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 customer set cst_Year='"+sCustYear+
"',cst_month='"+sCustMonth+
"',cst_address='"+sCustAddr2+
"',cst_zip_code='"+sCustZip+
"',cst_ph_office='"+sCustPhOff2+
"',cst_ph_home='"+sCustPhHom2+
"',cst_mobile='"+sCustMobile+
"',cst_email='"+sCustEmail+
"',cst_discount="+fCustDis+
",cst_crt_date=to_date('"+sCustCrtDt+
"','yyyy-mm-dd'),cst_upt_date=to_date('"+sCustUptDt+
"','yyyy-mm-dd') where cst_id='"+sCustID+"'";
//out.println(sUpdate+"
");
stmt = conn.createStatement();
stmt.execute(sUpdate);
conn.commit();
out.println("修改顧客"+sCustName2+"資訊完成");
}
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-799821/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- JSP(4) - 增加客戶模組JS
- JSP(10) - 修改商品資訊模組JS
- Transmit 5 for MacFTP客戶端MITMacFTP客戶端
- 關於客戶端資訊流思考客戶端
- JSP(8) - 按卡號查詢顧客資訊JS
- MacFTP客戶端——Transmit 5 for MacMacFTP客戶端MIT
- Transmit 5 for Mac(FTP客戶端)MITMacFTP客戶端
- 急!!jsp可以啟動客戶端應用程式嗎?JS客戶端
- RabbitMQ Go客戶端教程5——topicMQGo客戶端
- 客戶端JavaScript的5個弊端客戶端JavaScript
- 修改CAS客戶端 使用簡單HTTP協議客戶端HTTP協議
- 社會化客戶關係管理–資訊圖
- 企業管理客戶的難點 藉助資訊化技術管理客戶的策略
- 如何使用struts,在客戶端的jsp裡面有類似javascript的alert功能?如何使用struts,在客戶端的jsp裡面有類似javascri客戶端JSJavaScript
- 使用 Python 的 Tkinter模組 開發 IRC 客戶端Python客戶端
- CRM系統快速管理、檢視客戶全景資訊
- 還在用Excel維護客戶資訊?你OUT了Excel
- js獲取瀏覽器資訊和客戶端硬體資訊(一)JS瀏覽器客戶端
- windows tftp客戶端,5步掌握win7開啟tftp客戶端的方法教程WindowsFTP客戶端Win7
- CRM理想關鍵步驟:完善客戶資訊分析能力
- JSP(11) - 退貨模組JS
- JSP(9) - 增加商品模組JS
- JSP(7) - 銷售模組JS
- JSP(6) - 進貨模組JS
- Proxifier for Mac(socks5全域性代理客戶端)Mac客戶端
- 如何利用sockserver模組程式設計實現客戶端併發Server程式設計客戶端
- psycopg2 修改資料庫客戶端字符集資料庫客戶端
- 如何自動檢索客戶資訊斷融,CRM系統?
- C# 獲取客戶端資訊 /asp.net/WebService/WebFormC#客戶端ASP.NETWebORM
- 黑客如何竊取花旗銀行的客戶資訊黑客
- 可擴充套件客戶資訊語言 (xCIL) 簡介 (轉)套件
- 智慧手機幫助廣告客戶與顧客建立聯絡–資料資訊圖
- Git使用經驗總結5-修改提交資訊Git
- 如何使用struts,在客戶端的jsp裡面有類似javascript的alert功能?客戶端JSJavaScript
- Springboot 多模組 jspSpring BootJS
- JSP(12) - 商品處理模組JS
- Transmit 5 for Mac(FTP客戶端)mac中文最新版MITMacFTP客戶端
- Transmit 5 for Mac(FTP客戶端)5.10.3中文版MITMacFTP客戶端