首页 > 数字化转型 > ERP > JSP(5) - 修改客户信息模块
分三页。先按顾客编号检索出顾客信息,修改顾客信息后存入数据库。
要点:
1) 从数据库检索出数据,用
ResultSet rs = null;
......
stmt = conn.createStatement();
rs = stmt.executeQuery(sQuery);
while(rs.next()) { ...... }
<%@ 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 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("
检索顾客信息失败!
");finally{
if(stmt != null) stmt.close();
conn.close();
}
%>
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 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("
修改顾客信息失败!
");%>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/207/viewspace-799821/ ,如需转载,请注明出处,否则将追究法律责任。