ITPub博客

首页 > 数字化转型 > ERP > JSP(5) - 修改客户信息模块

JSP(5) - 修改客户信息模块

原创 ERP 作者:zhyuh 时间:2005-06-08 16:05:12 0 删除 编辑

分三页。先按顾客编号检索出顾客信息,修改顾客信息后存入数据库。

要点:
1) 从数据库检索出数据,用
ResultSet rs = null;
......
stmt = conn.createStatement();
rs = stmt.executeQuery(sQuery);
while(rs.next()) { ...... }

[@more@]

upt_cust1.jsp:

<%@ page contentType="text/html; charset=GBK" %>



<br />请输入要修改的顾客的卡号


<!---->



请输入要修改的客户卡号

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




upt_cust2.jsp:

<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.DateFormat" %>
<%
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();
}

%>


修改顾客信息


客户卡号:     

客户姓名:     

性别:         

出生年月:     

通讯地址:     

邮政编码:     

办公室电话:   

家庭电话:     

手机:         

Email:        

折扣:         %

累计购物金额:

增加日期:     

最后修改日起:


           







upt_cust3.jsp:

<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.DateFormat" %>
<%
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(6) - 进货模块
请登录后发表评论 登录
全部评论
  • 博文量
    233
  • 访问量
    2008691